diff --git a/HandyControl/Controls/Attach/TitleElement.cs b/HandyControl/Controls/Attach/TitleElement.cs index c5a1a711..5fab90ea 100644 --- a/HandyControl/Controls/Attach/TitleElement.cs +++ b/HandyControl/Controls/Attach/TitleElement.cs @@ -13,5 +13,23 @@ namespace HandyControl.Controls public static Brush GetBackground(DependencyObject element) => (Brush) element.GetValue(BackgroundProperty); + + public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached( + "Foreground", typeof(Brush), typeof(TitleElement), new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.Inherits)); + + public static void SetForeground(DependencyObject element, Brush value) + => element.SetValue(ForegroundProperty, value); + + public static Brush GetForeground(DependencyObject element) + => (Brush) element.GetValue(ForegroundProperty); + + public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.RegisterAttached( + "BorderBrush", typeof(Brush), typeof(TitleElement), new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.Inherits)); + + public static void SetBorderBrush(DependencyObject element, Brush value) + => element.SetValue(BorderBrushProperty, value); + + public static Brush GetBorderBrush(DependencyObject element) + => (Brush) element.GetValue(BorderBrushProperty); } } \ No newline at end of file diff --git a/HandyControl/Controls/Other/RadioGroup.cs b/HandyControl/Controls/Other/RadioGroup.cs new file mode 100644 index 00000000..86f957f7 --- /dev/null +++ b/HandyControl/Controls/Other/RadioGroup.cs @@ -0,0 +1,52 @@ +using System.Windows; +using System.Windows.Controls; +using HandyControl.Tools; + +namespace HandyControl.Controls +{ + public class RadioGroup : ItemsControl + { + protected override DependencyObject GetContainerForItemOverride() => new RadioButton(); + + protected override bool IsItemItsOwnContainerOverride(object item) => item is RadioButton; + + //public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register( + // "GroupName", typeof(string), typeof(RadioGroup), new PropertyMetadata(default(string))); + + //public string GroupName + //{ + // get => (string) GetValue(GroupNameProperty); + // set => SetValue(GroupNameProperty, value); + //} + + public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( + "Orientation", typeof(Orientation), typeof(RadioGroup), new PropertyMetadata(default(Orientation))); + + public Orientation Orientation + { + get => (Orientation)GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } + + public static readonly DependencyProperty ItemStyleSelectorProperty = DependencyProperty.Register( + "ItemStyleSelector", typeof(StyleSelector), typeof(RadioGroup), new PropertyMetadata(new RadioGroupItemStyleSelector())); + + public StyleSelector ItemStyleSelector + { + get => (StyleSelector)GetValue(ItemStyleSelectorProperty); + set => SetValue(ItemStyleSelectorProperty, value); + } + + protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved) + { + base.OnVisualChildrenChanged(visualAdded, visualRemoved); + + var count = Items.Count; + for (int i = 0; i < count; i++) + { + var item = (RadioButton)Items[i]; + item.Style = ItemStyleSelector?.SelectStyle(item, this); + } + } + } +} \ No newline at end of file diff --git a/HandyControl/Data/ResourceToken.cs b/HandyControl/Data/ResourceToken.cs index 4af1c112..6abeff0b 100644 --- a/HandyControl/Data/ResourceToken.cs +++ b/HandyControl/Data/ResourceToken.cs @@ -38,5 +38,29 @@ public static readonly string AddTagButtonStyle = nameof(AddTagButtonStyle); + public static readonly string RadioGroupItemDefault = nameof(RadioGroupItemDefault); + + public static readonly string RadioGroupItemSingle = nameof(RadioGroupItemSingle); + + public static readonly string RadioGroupItemHorizontalFirst = nameof(RadioGroupItemHorizontalFirst); + + public static readonly string RadioGroupItemHorizontalLast = nameof(RadioGroupItemHorizontalLast); + + public static readonly string RadioGroupItemVerticalFirst = nameof(RadioGroupItemVerticalFirst); + + public static readonly string RadioGroupItemVerticalLast = nameof(RadioGroupItemVerticalLast); + + public static readonly string TabItemCapsuleDefault = nameof(TabItemCapsuleDefault); + + public static readonly string TabItemCapsuleSingle = nameof(TabItemCapsuleSingle); + + public static readonly string TabItemCapsuleHorizontalFirst = nameof(TabItemCapsuleHorizontalFirst); + + public static readonly string TabItemCapsuleHorizontalLast = nameof(TabItemCapsuleHorizontalLast); + + public static readonly string TabItemCapsuleVerticalFirst = nameof(TabItemCapsuleVerticalFirst); + + public static readonly string TabItemCapsuleVerticalLast = nameof(TabItemCapsuleVerticalLast); + } } \ No newline at end of file diff --git a/HandyControl/Data/ResourceToken.tt b/HandyControl/Data/ResourceToken.tt index a3b2192e..7f3f90d6 100644 --- a/HandyControl/Data/ResourceToken.tt +++ b/HandyControl/Data/ResourceToken.tt @@ -27,7 +27,19 @@ var styleList = new List "ButtonCustom", "PaginationButtonStyle", "CustomWindowStyle", - "AddTagButtonStyle" + "AddTagButtonStyle", + "RadioGroupItemDefault", + "RadioGroupItemSingle", + "RadioGroupItemHorizontalFirst", + "RadioGroupItemHorizontalLast", + "RadioGroupItemVerticalFirst", + "RadioGroupItemVerticalLast", + "TabItemCapsuleDefault", + "TabItemCapsuleSingle", + "TabItemCapsuleHorizontalFirst", + "TabItemCapsuleHorizontalLast", + "TabItemCapsuleVerticalFirst", + "TabItemCapsuleVerticalLast" }; #> namespace HandyControl.Data diff --git a/HandyControl/Data/ValueBoxes.cs b/HandyControl/Data/ValueBoxes.cs index dbf21d59..b1d1aef2 100644 --- a/HandyControl/Data/ValueBoxes.cs +++ b/HandyControl/Data/ValueBoxes.cs @@ -17,6 +17,10 @@ internal static object DoubleNeg1Box = -1.0; + internal static object Int0Box = 0; + + internal static object Int1Box = 1; + internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox; } } \ No newline at end of file diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index a0f6d12f..16760bb7 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -62,6 +62,7 @@ + @@ -105,7 +106,7 @@ - + @@ -147,8 +148,8 @@ - - + + @@ -212,8 +213,8 @@ True Lang.en.resx - - + + @@ -228,11 +229,13 @@ + - - - + + + + @@ -295,6 +298,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -507,6 +514,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -620,5 +631,6 @@ + \ No newline at end of file diff --git a/HandyControl/Properties/Langs/Lang.Designer.cs b/HandyControl/Properties/Langs/Lang.Designer.cs index e393484a..37f04b41 100644 --- a/HandyControl/Properties/Langs/Lang.Designer.cs +++ b/HandyControl/Properties/Langs/Lang.Designer.cs @@ -47,7 +47,7 @@ namespace HandyControl.Properties.Langs { } /// - /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性 /// 重写当前线程的 CurrentUICulture 属性。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] diff --git a/HandyControl/Themes/Styles/Base/RadioButtonBaseStyle.xaml b/HandyControl/Themes/Styles/Base/RadioButtonBaseStyle.xaml index b90c8d32..d1b7764e 100644 --- a/HandyControl/Themes/Styles/Base/RadioButtonBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/RadioButtonBaseStyle.xaml @@ -1,5 +1,11 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:controls="clr-namespace:HandyControl.Controls" + xmlns:system="clr-namespace:System;assembly=mscorlib"> + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Base/RadioGroupBaseStyle.xaml b/HandyControl/Themes/Styles/Base/RadioGroupBaseStyle.xaml new file mode 100644 index 00000000..f531d865 --- /dev/null +++ b/HandyControl/Themes/Styles/Base/RadioGroupBaseStyle.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Base/TabControlBaseStyle.xaml b/HandyControl/Themes/Styles/Base/TabControlBaseStyle.xaml index fcb9fd8e..bd3d2a23 100644 --- a/HandyControl/Themes/Styles/Base/TabControlBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/TabControlBaseStyle.xaml @@ -1,5 +1,11 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:controls="clr-namespace:HandyControl.Controls" + xmlns:system="clr-namespace:System;assembly=mscorlib"> + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/RadioButton.xaml b/HandyControl/Themes/Styles/RadioButton.xaml index e4f3dd77..3424f948 100644 --- a/HandyControl/Themes/Styles/RadioButton.xaml +++ b/HandyControl/Themes/Styles/RadioButton.xaml @@ -1,6 +1,6 @@ - + @@ -71,4 +71,28 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/RadioGroup.xaml b/HandyControl/Themes/Styles/RadioGroup.xaml new file mode 100644 index 00000000..3a6d2a00 --- /dev/null +++ b/HandyControl/Themes/Styles/RadioGroup.xaml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Style.xaml b/HandyControl/Themes/Styles/Style.xaml index 1622e0fc..2105e783 100644 --- a/HandyControl/Themes/Styles/Style.xaml +++ b/HandyControl/Themes/Styles/Style.xaml @@ -46,6 +46,7 @@ + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/TabControl.xaml b/HandyControl/Themes/Styles/TabControl.xaml index b81a0a96..1c319e46 100644 --- a/HandyControl/Themes/Styles/TabControl.xaml +++ b/HandyControl/Themes/Styles/TabControl.xaml @@ -2,7 +2,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls" xmlns:langs="clr-namespace:HandyControl.Properties.Langs" - xmlns:interactivity="clr-namespace:HandyControl.Interactivity"> + xmlns:interactivity="clr-namespace:HandyControl.Interactivity" + xmlns:tools="clr-namespace:HandyControl.Tools"> @@ -145,4 +146,65 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Tools/AnimationHelper.cs b/HandyControl/Tools/Helper/AnimationHelper.cs similarity index 100% rename from HandyControl/Tools/AnimationHelper.cs rename to HandyControl/Tools/Helper/AnimationHelper.cs diff --git a/HandyControl/Tools/ArithmeticHelper.cs b/HandyControl/Tools/Helper/ArithmeticHelper.cs similarity index 100% rename from HandyControl/Tools/ArithmeticHelper.cs rename to HandyControl/Tools/Helper/ArithmeticHelper.cs diff --git a/HandyControl/Tools/ColorHelper.cs b/HandyControl/Tools/Helper/ColorHelper.cs similarity index 100% rename from HandyControl/Tools/ColorHelper.cs rename to HandyControl/Tools/Helper/ColorHelper.cs diff --git a/HandyControl/Tools/ExternDllHelper.cs b/HandyControl/Tools/Helper/ExternDllHelper.cs similarity index 100% rename from HandyControl/Tools/ExternDllHelper.cs rename to HandyControl/Tools/Helper/ExternDllHelper.cs diff --git a/HandyControl/Tools/ResourceHelper.cs b/HandyControl/Tools/Helper/ResourceHelper.cs similarity index 100% rename from HandyControl/Tools/ResourceHelper.cs rename to HandyControl/Tools/Helper/ResourceHelper.cs diff --git a/HandyControl/Tools/SingleOpenHelper.cs b/HandyControl/Tools/Helper/SingleOpenHelper.cs similarity index 100% rename from HandyControl/Tools/SingleOpenHelper.cs rename to HandyControl/Tools/Helper/SingleOpenHelper.cs diff --git a/HandyControl/Tools/ValidateHelper.cs b/HandyControl/Tools/Helper/ValidateHelper.cs similarity index 100% rename from HandyControl/Tools/ValidateHelper.cs rename to HandyControl/Tools/Helper/ValidateHelper.cs diff --git a/HandyControl/Tools/VisualHelper.cs b/HandyControl/Tools/Helper/VisualHelper.cs similarity index 100% rename from HandyControl/Tools/VisualHelper.cs rename to HandyControl/Tools/Helper/VisualHelper.cs diff --git a/HandyControl/Tools/StyleSelector/RadioGroupItemStyleSelector.cs b/HandyControl/Tools/StyleSelector/RadioGroupItemStyleSelector.cs new file mode 100644 index 00000000..002ba5ed --- /dev/null +++ b/HandyControl/Tools/StyleSelector/RadioGroupItemStyleSelector.cs @@ -0,0 +1,37 @@ +using System.Windows; +using System.Windows.Controls; +using HandyControl.Controls; +using HandyControl.Data; + +namespace HandyControl.Tools +{ + public class RadioGroupItemStyleSelector : StyleSelector + { + public override Style SelectStyle(object item, DependencyObject container) + { + if (container is RadioGroup radioGroup && item is UIElement radioButton) + { + var count = radioGroup.Items.Count; + if (count == 1) + { + return ResourceHelper.GetResource