now hc styles can be referenced in window.resource
by the way, supported multiple themes at the same time, It may be related to #574
This commit is contained in:
1 parent
3be68c3010
commit
d997aee5f7
23 files changed
+161
-129
No files matched your search
@@ -11,9 +11,9 @@ namespace HandyControlDemo.Resources
|
||||
public override ResourceDictionary GetSkin(SkinType skinType) =>
|
||||
ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skinType);
|
||||
|
||||
public override ResourceDictionary GetTheme() => new ResourceDictionary
|
||||
public override ResourceDictionary GetTheme() => new Lazy<ResourceDictionary>(() => new ResourceDictionary
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml")
|
||||
};
|
||||
}).Value;
|
||||
}
|
||||
}
|
||||
@@ -455,7 +455,7 @@ namespace HandyControl.Controls
|
||||
var button = new Button
|
||||
{
|
||||
Margin = new Thickness(6),
|
||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.ButtonCustom),
|
||||
Style = ResourceHelper.GetResourceInternal<Style>(ResourceToken.ButtonCustom),
|
||||
Content = new Border
|
||||
{
|
||||
Background = brush,
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
};
|
||||
|
||||
PanelElement.SetFluidMoveBehavior(panel, ResourceHelper.GetResource<FluidMoveBehavior>(ResourceToken.BehaviorXY400));
|
||||
PanelElement.SetFluidMoveBehavior(panel, ResourceHelper.GetResourceInternal<FluidMoveBehavior>(ResourceToken.BehaviorXY400));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -372,8 +372,8 @@ namespace HandyControl.Controls
|
||||
{
|
||||
Message = growlInfo.Message,
|
||||
Time = DateTime.Now,
|
||||
Icon = ResourceHelper.GetResource<Geometry>(growlInfo.IconKey),
|
||||
IconBrush = ResourceHelper.GetResource<Brush>(growlInfo.IconBrushKey),
|
||||
Icon = ResourceHelper.GetResourceInternal<Geometry>(growlInfo.IconKey),
|
||||
IconBrush = ResourceHelper.GetResourceInternal<Brush>(growlInfo.IconBrushKey),
|
||||
_showCloseButton = growlInfo.ShowCloseButton,
|
||||
ActionBeforeClose = growlInfo.ActionBeforeClose,
|
||||
_staysOpen = growlInfo.StaysOpen,
|
||||
@@ -407,8 +407,8 @@ namespace HandyControl.Controls
|
||||
{
|
||||
Message = growlInfo.Message,
|
||||
Time = DateTime.Now,
|
||||
Icon = ResourceHelper.GetResource<Geometry>(growlInfo.IconKey),
|
||||
IconBrush = ResourceHelper.GetResource<Brush>(growlInfo.IconBrushKey),
|
||||
Icon = ResourceHelper.GetResourceInternal<Geometry>(growlInfo.IconKey),
|
||||
IconBrush = ResourceHelper.GetResourceInternal<Brush>(growlInfo.IconBrushKey),
|
||||
_showCloseButton = growlInfo.ShowCloseButton,
|
||||
ActionBeforeClose = growlInfo.ActionBeforeClose,
|
||||
_staysOpen = growlInfo.StaysOpen,
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
Stretch = Stretch.UniformToFill
|
||||
}
|
||||
: ResourceHelper.GetResource<Brush>("SecondaryRegionBrush");
|
||||
: ResourceHelper.GetResourceInternal<Brush>("SecondaryRegionBrush");
|
||||
}
|
||||
|
||||
public ImageSource Source
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
return new RadioButton
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.PaginationButtonStyle),
|
||||
Style = ResourceHelper.GetResourceInternal<Style>(ResourceToken.PaginationButtonStyle),
|
||||
Content = page.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
else if (Application.Current != null)
|
||||
{
|
||||
ResourceHelper.GetResource<Storyboard>($"{TransitionMode.ToString()}Transition")?.Begin(_contentPresenter);
|
||||
ResourceHelper.GetResourceInternal<Storyboard>($"{TransitionMode.ToString()}Transition")?.Begin(_contentPresenter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -14,9 +14,9 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.ComboBox
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("ComboBoxCapsule"),
|
||||
Style = ResourceHelper.GetResourceInternal<Style>("ComboBoxCapsule"),
|
||||
ItemsSource = Enum.GetValues(propertyItem.PropertyType),
|
||||
ItemTemplateSelector = ResourceHelper.GetResource<DataTemplateSelector>("HorizontalAlignmentPathTemplateSelector"),
|
||||
ItemTemplateSelector = ResourceHelper.GetResourceInternal<DataTemplateSelector>("HorizontalAlignmentPathTemplateSelector"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left
|
||||
};
|
||||
|
||||
@@ -48,16 +48,16 @@ namespace HandyControl.Controls
|
||||
switch (horizontalAlignment)
|
||||
{
|
||||
case HorizontalAlignment.Left:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignLeftGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignLeftGeometry"));
|
||||
break;
|
||||
case HorizontalAlignment.Center:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignHCenterGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignHCenterGeometry"));
|
||||
break;
|
||||
case HorizontalAlignment.Right:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignRightGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignRightGeometry"));
|
||||
break;
|
||||
case HorizontalAlignment.Stretch:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignHStretchGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignHStretchGeometry"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,6 +15,6 @@ namespace HandyControl.Controls
|
||||
|
||||
public override BindingMode GetBindingMode(PropertyItem propertyItem) => BindingMode.OneWay;
|
||||
|
||||
protected override IValueConverter GetConverter(PropertyItem propertyItem) => ResourceHelper.GetResource<IValueConverter>("Object2StringConverter");
|
||||
protected override IValueConverter GetConverter(PropertyItem propertyItem) => ResourceHelper.GetResourceInternal<IValueConverter>("Object2StringConverter");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new ToggleButton
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("ToggleButtonSwitch"),
|
||||
Style = ResourceHelper.GetResourceInternal<Style>("ToggleButtonSwitch"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
+6
-6
@@ -14,9 +14,9 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.ComboBox
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("ComboBoxCapsule"),
|
||||
Style = ResourceHelper.GetResourceInternal<Style>("ComboBoxCapsule"),
|
||||
ItemsSource = Enum.GetValues(propertyItem.PropertyType),
|
||||
ItemTemplateSelector = ResourceHelper.GetResource<DataTemplateSelector>("VerticalAlignmentPathTemplateSelector"),
|
||||
ItemTemplateSelector = ResourceHelper.GetResourceInternal<DataTemplateSelector>("VerticalAlignmentPathTemplateSelector"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left
|
||||
};
|
||||
|
||||
@@ -48,16 +48,16 @@ namespace HandyControl.Controls
|
||||
switch (verticalAlignment)
|
||||
{
|
||||
case VerticalAlignment.Top:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignTopGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignTopGeometry"));
|
||||
break;
|
||||
case VerticalAlignment.Center:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignVCenterGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignVCenterGeometry"));
|
||||
break;
|
||||
case VerticalAlignment.Bottom:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignBottomGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignBottomGeometry"));
|
||||
break;
|
||||
case VerticalAlignment.Stretch:
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResource<Geometry>("AlignVStretchGeometry"));
|
||||
factory.SetValue(Path.DataProperty, ResourceHelper.GetResourceInternal<Geometry>("AlignVStretchGeometry"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public ScreenshotWindow(Screenshot screenshot)
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.Window4ScreenshotStyle);
|
||||
Style = ResourceHelper.GetResourceInternal<Style>(ResourceToken.Window4ScreenshotStyle);
|
||||
_screenshot = screenshot;
|
||||
DataContext = this;
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace HandyControl.Controls
|
||||
menu.SetBinding(VisibilityProperty, new Binding(ShowContextMenuProperty.Name)
|
||||
{
|
||||
Source = this,
|
||||
Converter = ResourceHelper.GetResource<IValueConverter>(ResourceToken.Boolean2VisibilityConverter)
|
||||
Converter = ResourceHelper.GetResourceInternal<IValueConverter>(ResourceToken.Boolean2VisibilityConverter)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace HandyControl.Controls
|
||||
if (versionInfo < SystemVersionInfo.Windows10 ||
|
||||
versionInfo >= SystemVersionInfo.Windows10_1903)
|
||||
{
|
||||
var colorValue = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue);
|
||||
var colorValue = ResourceHelper.GetResourceInternal<uint>(ResourceToken.BlurGradientValue);
|
||||
var color = ColorHelper.ToColor(colorValue);
|
||||
color = Color.FromRgb(color.R, color.G, color.B);
|
||||
window.Background = new SolidColorBrush(color);
|
||||
@@ -44,7 +44,7 @@ namespace HandyControl.Controls
|
||||
: InteropValues.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
||||
|
||||
accentPolicy.AccentFlags = 2;
|
||||
accentPolicy.GradientColor = ResourceHelper.GetResource<uint>(ResourceToken.BlurGradientValue);
|
||||
accentPolicy.GradientColor = ResourceHelper.GetResourceInternal<uint>(ResourceToken.BlurGradientValue);
|
||||
|
||||
var accentPtr = Marshal.AllocHGlobal(accentPolicySize);
|
||||
Marshal.StructureToPtr(accentPolicy, accentPtr, false);
|
||||
|
||||
@@ -248,8 +248,8 @@ namespace HandyControl.Controls
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.SuccessGeometry);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.SuccessBrush);
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(ResourceToken.SuccessGeometry);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResourceInternal<Brush>(ResourceToken.SuccessBrush);
|
||||
SystemSounds.Asterisk.Play();
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
@@ -330,8 +330,8 @@ namespace HandyControl.Controls
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.FatalGeometry);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryTextBrush);
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(ResourceToken.FatalGeometry);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResourceInternal<Brush>(ResourceToken.PrimaryTextBrush);
|
||||
SystemSounds.Asterisk.Play();
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
@@ -375,13 +375,13 @@ namespace HandyControl.Controls
|
||||
if (!string.IsNullOrEmpty(info.IconKey))
|
||||
{
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(info.IconKey);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(info.IconBrushKey);
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(info.IconKey);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResourceInternal<Brush>(info.IconBrushKey);
|
||||
}
|
||||
|
||||
if (info.StyleKey != null)
|
||||
{
|
||||
messageBox.Style = ResourceHelper.GetResource<Style>(info.StyleKey);
|
||||
messageBox.Style = ResourceHelper.GetResourceInternal<Style>(info.StyleKey);
|
||||
}
|
||||
SystemSounds.Asterisk.Play();
|
||||
messageBox.ShowDialog();
|
||||
@@ -477,7 +477,7 @@ namespace HandyControl.Controls
|
||||
IsDefault = true,
|
||||
Content = Lang.Confirm,
|
||||
Command = ControlCommands.Confirm,
|
||||
Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle")
|
||||
Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle")
|
||||
};
|
||||
|
||||
break;
|
||||
@@ -499,15 +499,15 @@ namespace HandyControl.Controls
|
||||
|
||||
if (defaultResult == MessageBoxResult.Cancel)
|
||||
{
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonOk.IsDefault = true;
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -528,15 +528,15 @@ namespace HandyControl.Controls
|
||||
|
||||
if (defaultResult == MessageBoxResult.No)
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.IsDefault = true;
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -565,24 +565,24 @@ namespace HandyControl.Controls
|
||||
|
||||
if (defaultResult == MessageBoxResult.No)
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.IsDefault = true;
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
else if (defaultResult == MessageBoxResult.Cancel)
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.IsDefault = true;
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -616,8 +616,8 @@ namespace HandyControl.Controls
|
||||
|
||||
if (string.IsNullOrEmpty(iconKey)) return;
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(iconKey);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(iconBrushKey);
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(iconKey);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResourceInternal<Brush>(iconBrushKey);
|
||||
}
|
||||
|
||||
private static bool IsValidMessageBoxButton(MessageBoxButton value)
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace HandyControl.Controls
|
||||
WindowStyle = WindowStyle.None,
|
||||
ContentStr = message,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
Background = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryBrush)
|
||||
Background = ResourceHelper.GetResourceInternal<Brush>(ResourceToken.PrimaryBrush)
|
||||
};
|
||||
window.Show();
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace HandyControl.Controls
|
||||
|
||||
static Window()
|
||||
{
|
||||
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(ResourceHelper.GetResource<Style>(ResourceToken.WindowWin10)));
|
||||
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(ResourceHelper.GetResourceInternal<Style>(ResourceToken.WindowWin10)));
|
||||
}
|
||||
|
||||
public Window()
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace HandyControl.Properties.Langs
|
||||
{
|
||||
public class LangProvider : INotifyPropertyChanged
|
||||
{
|
||||
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("Langs");
|
||||
internal static LangProvider Instance => ResourceHelper.GetResourceInternal<LangProvider>("Langs");
|
||||
|
||||
private static string CultureInfoStr;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace HandyControl.Properties.Langs
|
||||
{
|
||||
public class LangProvider : INotifyPropertyChanged
|
||||
{
|
||||
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("Langs");
|
||||
internal static LangProvider Instance => ResourceHelper.GetResourceInternal<LangProvider>("Langs");
|
||||
|
||||
private static string CultureInfoStr;
|
||||
|
||||
@@ -81,4 +81,4 @@ namespace HandyControl.Properties.Langs
|
||||
|
||||
<#}#>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
@@ -11,11 +12,11 @@ namespace HandyControl.Themes
|
||||
{
|
||||
if (DesignerHelper.IsInDesignMode)
|
||||
{
|
||||
MergedDictionaries.Add(new ResourceDictionary
|
||||
MergedDictionaries.Add(new()
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml")
|
||||
});
|
||||
MergedDictionaries.Add(new ResourceDictionary
|
||||
MergedDictionaries.Add(new()
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
|
||||
});
|
||||
@@ -48,14 +49,51 @@ namespace HandyControl.Themes
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SkinProperty = DependencyProperty.RegisterAttached(
|
||||
"Skin", typeof(SkinType), typeof(Theme), new PropertyMetadata(default(SkinType), OnSkinChanged));
|
||||
|
||||
private static void OnSkinChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is FrameworkElement element)
|
||||
{
|
||||
var skin = (SkinType) e.NewValue;
|
||||
|
||||
if (element.Resources is Theme resource)
|
||||
{
|
||||
resource.Skin = skin;
|
||||
}
|
||||
else
|
||||
{
|
||||
var themes = element.Resources.MergedDictionaries.OfType<Theme>();
|
||||
if (!themes.Any())
|
||||
{
|
||||
element.Resources.MergedDictionaries.Add(new Theme
|
||||
{
|
||||
Skin = skin
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var subResource in element.Resources.MergedDictionaries.OfType<Theme>())
|
||||
{
|
||||
subResource.Skin = skin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSkin(DependencyObject element, SkinType value)
|
||||
=> element.SetValue(SkinProperty, value);
|
||||
|
||||
public static SkinType GetSkin(DependencyObject element)
|
||||
=> (SkinType) element.GetValue(SkinProperty);
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ResourceDictionary GetSkin(SkinType skinType) => ResourceHelper.GetSkin(skinType);
|
||||
|
||||
public virtual ResourceDictionary GetTheme() => new ResourceDictionary
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
|
||||
};
|
||||
public virtual ResourceDictionary GetTheme() => ResourceHelper.GetTheme();
|
||||
|
||||
private void UpdateResource()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
@@ -13,29 +12,6 @@ namespace HandyControl.Tools
|
||||
/// </summary>
|
||||
public class ResourceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取字符串
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetString(string key) => Application.Current.TryFindResource(key) as string;
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串
|
||||
/// </summary>
|
||||
/// <param name="separator"></param>
|
||||
/// <param name="keyArr"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetString(string separator = ";", params string[] keyArr) =>
|
||||
string.Join(separator, keyArr.Select(key => Application.Current.TryFindResource(key) as string).ToList());
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串
|
||||
/// </summary>
|
||||
/// <param name="keyArr"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> GetStringList(params string[] keyArr) => keyArr.Select(key => Application.Current.TryFindResource(key) as string).ToList();
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源
|
||||
/// </summary>
|
||||
@@ -51,23 +27,29 @@ namespace HandyControl.Tools
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取HandyControl皮肤
|
||||
/// </summary>
|
||||
/// <param name="skin"></param>
|
||||
/// <returns></returns>
|
||||
public static ResourceDictionary GetSkin(SkinType skin) => new ResourceDictionary
|
||||
internal static T GetResourceInternal<T>(string key)
|
||||
{
|
||||
Source = new Uri($"pack://application:,,,/HandyControl;component/Themes/Skin{skin.ToString()}.xaml")
|
||||
};
|
||||
if (GetTheme()[key] is T resource)
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static Theme GetTheme(string name, ResourceDictionary resourceDictionary)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name) || resourceDictionary == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return resourceDictionary.MergedDictionaries.OfType<Theme>().FirstOrDefault(item => Equals(item.Name, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取皮肤
|
||||
/// </summary>
|
||||
/// <param name="assembly"></param>
|
||||
/// <param name="themePath"></param>
|
||||
/// <param name="skin"></param>
|
||||
/// <returns></returns>
|
||||
public static ResourceDictionary GetSkin(Assembly assembly, string themePath, SkinType skin)
|
||||
{
|
||||
try
|
||||
@@ -87,11 +69,23 @@ namespace HandyControl.Tools
|
||||
}
|
||||
}
|
||||
|
||||
public static Theme GetTheme(string name, ResourceDictionary resourceDictionary)
|
||||
/// <summary>
|
||||
/// get HandyControl skin
|
||||
/// </summary>
|
||||
/// <param name="skin"></param>
|
||||
/// <returns></returns>
|
||||
public static ResourceDictionary GetSkin(SkinType skin) => new()
|
||||
{
|
||||
if (string.IsNullOrEmpty(name) || resourceDictionary == null) return null;
|
||||
return resourceDictionary.MergedDictionaries.OfType<Theme>()
|
||||
.FirstOrDefault(item => Equals(item.Name, name));
|
||||
}
|
||||
Source = new Uri($"pack://application:,,,/HandyControl;component/Themes/Skin{skin}.xaml")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// get HandyControl theme
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ResourceDictionary GetTheme() => new Lazy<ResourceDictionary>(() => new ResourceDictionary
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
|
||||
}).Value;
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -20,19 +20,19 @@ namespace HandyControl.Tools
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemSingle);
|
||||
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.RadioGroupItemSingle);
|
||||
}
|
||||
|
||||
var index = buttonGroup.Items.IndexOf(buttonBase);
|
||||
return buttonGroup.Orientation == Orientation.Horizontal
|
||||
? index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.RadioGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.RadioGroupItemHorizontalLast
|
||||
: ResourceToken.RadioGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.RadioGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.RadioGroupItemVerticalLast
|
||||
: ResourceToken.RadioGroupItemDefault);
|
||||
}
|
||||
@@ -41,19 +41,19 @@ namespace HandyControl.Tools
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<Style>(ResourceToken.ButtonGroupItemSingle);
|
||||
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.ButtonGroupItemSingle);
|
||||
}
|
||||
|
||||
var index = buttonGroup.Items.IndexOf(buttonBase);
|
||||
return buttonGroup.Orientation == Orientation.Horizontal
|
||||
? index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ButtonGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.ButtonGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.ButtonGroupItemHorizontalLast
|
||||
: ResourceToken.ButtonGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.ButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.ButtonGroupItemVerticalLast
|
||||
: ResourceToken.ButtonGroupItemDefault);
|
||||
}
|
||||
@@ -62,19 +62,19 @@ namespace HandyControl.Tools
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<Style>(ResourceToken.ToggleButtonGroupItemSingle);
|
||||
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.ToggleButtonGroupItemSingle);
|
||||
}
|
||||
|
||||
var index = buttonGroup.Items.IndexOf(buttonBase);
|
||||
return buttonGroup.Orientation == Orientation.Horizontal
|
||||
? index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ToggleButtonGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.ToggleButtonGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.ToggleButtonGroupItemHorizontalLast
|
||||
: ResourceToken.ToggleButtonGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ToggleButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.ToggleButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.ToggleButtonGroupItemVerticalLast
|
||||
: ResourceToken.ToggleButtonGroupItemDefault);
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,13 +13,13 @@ namespace HandyControl.Tools
|
||||
var count = comboBox.Items.Count;
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<Style>(ResourceToken.ComboBoxItemCapsuleSingle);
|
||||
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.ComboBoxItemCapsuleSingle);
|
||||
}
|
||||
|
||||
var index = comboBox.ItemContainerGenerator.IndexFromContainer(comboBoxItem);
|
||||
return index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ComboBoxItemCapsuleHorizontalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceHelper.GetResourceInternal<Style>(ResourceToken.ComboBoxItemCapsuleHorizontalFirst)
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? ResourceToken.ComboBoxItemCapsuleHorizontalLast
|
||||
: ResourceToken.ComboBoxItemCapsuleDefault);
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@ namespace HandyControl.Tools
|
||||
var count = tabControl.Items.Count;
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<Style>(ResourceToken.TabItemCapsuleSingle);
|
||||
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.TabItemCapsuleSingle);
|
||||
}
|
||||
|
||||
var index = tabControl.ItemContainerGenerator.IndexFromContainer(tabItem);
|
||||
return index == 0
|
||||
? ResourceHelper.GetResource<Style>(
|
||||
? ResourceHelper.GetResourceInternal<Style>(
|
||||
tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
|
||||
? ResourceToken.TabItemCapsuleHorizontalFirst
|
||||
: ResourceToken.TabItemCapsuleVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
|
||||
? tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
|
||||
? ResourceToken.TabItemCapsuleHorizontalLast
|
||||
: ResourceToken.TabItemCapsuleVerticalLast
|
||||
|
||||
Reference in new issue
Block a user