add ButtonGroup
replaced RadioButton with ButtonGroup
This commit is contained in:
1 parent
aee1d2eff4
commit
73a17ecc79
32 files changed
+452
-81
No files matched your search
+7
-8
@@ -1,17 +1,16 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class RadioGroup : ItemsControl
|
||||
public class ButtonGroup : ItemsControl
|
||||
{
|
||||
protected override DependencyObject GetContainerForItemOverride() => new RadioButton();
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is RadioButton;
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is Button || item is RadioButton || item is ToggleButton;
|
||||
|
||||
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
|
||||
"Orientation", typeof(Orientation), typeof(RadioGroup), new PropertyMetadata(default(Orientation)));
|
||||
"Orientation", typeof(Orientation), typeof(ButtonGroup), new PropertyMetadata(default(Orientation)));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
@@ -20,7 +19,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ItemStyleSelectorProperty = DependencyProperty.Register(
|
||||
"ItemStyleSelector", typeof(StyleSelector), typeof(RadioGroup), new PropertyMetadata(new RadioGroupItemStyleSelector()));
|
||||
"ItemStyleSelector", typeof(StyleSelector), typeof(ButtonGroup), new PropertyMetadata(new ButtonGroupItemStyleSelector()));
|
||||
|
||||
public StyleSelector ItemStyleSelector
|
||||
{
|
||||
@@ -35,9 +34,9 @@ namespace HandyControl.Controls
|
||||
var count = Items.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var item = (RadioButton)Items[i];
|
||||
var item = (ButtonBase)Items[i];
|
||||
item.Style = ItemStyleSelector?.SelectStyle(item, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,30 @@
|
||||
|
||||
internal const string RadioGroupItemVerticalLast = nameof(RadioGroupItemVerticalLast);
|
||||
|
||||
internal const string ButtonGroupItemDefault = nameof(ButtonGroupItemDefault);
|
||||
|
||||
internal const string ButtonGroupItemSingle = nameof(ButtonGroupItemSingle);
|
||||
|
||||
internal const string ButtonGroupItemHorizontalFirst = nameof(ButtonGroupItemHorizontalFirst);
|
||||
|
||||
internal const string ButtonGroupItemHorizontalLast = nameof(ButtonGroupItemHorizontalLast);
|
||||
|
||||
internal const string ButtonGroupItemVerticalFirst = nameof(ButtonGroupItemVerticalFirst);
|
||||
|
||||
internal const string ButtonGroupItemVerticalLast = nameof(ButtonGroupItemVerticalLast);
|
||||
|
||||
internal const string ToggleButtonGroupItemDefault = nameof(ToggleButtonGroupItemDefault);
|
||||
|
||||
internal const string ToggleButtonGroupItemSingle = nameof(ToggleButtonGroupItemSingle);
|
||||
|
||||
internal const string ToggleButtonGroupItemHorizontalFirst = nameof(ToggleButtonGroupItemHorizontalFirst);
|
||||
|
||||
internal const string ToggleButtonGroupItemHorizontalLast = nameof(ToggleButtonGroupItemHorizontalLast);
|
||||
|
||||
internal const string ToggleButtonGroupItemVerticalFirst = nameof(ToggleButtonGroupItemVerticalFirst);
|
||||
|
||||
internal const string ToggleButtonGroupItemVerticalLast = nameof(ToggleButtonGroupItemVerticalLast);
|
||||
|
||||
internal const string TabItemCapsuleDefault = nameof(TabItemCapsuleDefault);
|
||||
|
||||
internal const string TabItemCapsuleSingle = nameof(TabItemCapsuleSingle);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\InfoElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PanelElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PasswordBoxAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ButtonGroup.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||
@@ -77,7 +78,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Growl.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\NotifyIcon.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Pagination.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\RadioGroup.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ScrollViewer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Shield.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\TransitioningContentControl.cs" />
|
||||
@@ -278,7 +278,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\RadioGroupItemStyleSelector.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ButtonGroupItemStyleSelector.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\TabItemCapsuleStyleSelector.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -466,7 +466,7 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\RadioGroupBaseStyle.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\ButtonGroupBaseStyle.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
@@ -662,7 +662,7 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\RadioGroup.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\ButtonGroup.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
||||
@@ -46,4 +46,45 @@
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="Button">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0"/>
|
||||
<Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
|
||||
<Setter Property="Padding" Value="10,0"/>
|
||||
<Setter Property="Margin" Value="-1,0,0,0"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border x:Name="BorderRoot" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<ContentPresenter x:Name="contentPresenter" TextElement.Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="TextElement.Foreground" Value="{DynamicResource PrimaryBrush}" TargetName="contentPresenter"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value="0.4"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding Orientation,RelativeSource={RelativeSource AncestorType=controls:ButtonGroup}}" Value="Vertical">
|
||||
<Setter Property="Margin" Value="0,-1,0,0"/>
|
||||
</DataTrigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource BorderBrush}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
+6
-5
@@ -2,24 +2,25 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ItemsPanelTemplate x:Key="RadioGroupHorizontalItemsPanelTemplate">
|
||||
<ItemsPanelTemplate x:Key="ButtonGroupHorizontalItemsPanelTemplate">
|
||||
<UniformGrid FocusVisualStyle="{x:Null}" Rows="1"/>
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
<ItemsPanelTemplate x:Key="RadioGroupVerticalItemsPanelTemplate">
|
||||
<ItemsPanelTemplate x:Key="ButtonGroupVerticalItemsPanelTemplate">
|
||||
<UniformGrid FocusVisualStyle="{x:Null}" Columns="1"/>
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
<Style x:Key="RadioGroupBaseStyle" TargetType="controls:RadioGroup">
|
||||
<Style x:Key="ButtonGroupBaseStyle" TargetType="controls:ButtonGroup">
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="ItemsPanel" Value="{StaticResource RadioGroupHorizontalItemsPanelTemplate}"/>
|
||||
<Setter Property="ItemsPanel" Value="{StaticResource ButtonGroupHorizontalItemsPanelTemplate}"/>
|
||||
<Setter Property="controls:TitleElement.BorderBrush" Value="{DynamicResource PrimaryBrush}"/>
|
||||
<Setter Property="controls:TitleElement.Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="controls:TitleElement.Foreground" Value="{DynamicResource PrimaryBrush}"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Orientation" Value="Vertical">
|
||||
<Setter Property="ItemsPanel" Value="{StaticResource RadioGroupVerticalItemsPanelTemplate}"/>
|
||||
<Setter Property="ItemsPanel" Value="{StaticResource ButtonGroupVerticalItemsPanelTemplate}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
@@ -196,9 +196,15 @@
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Panel.ZIndex" Value="{x:Static system:Int32.MaxValue}"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding Orientation,RelativeSource={RelativeSource AncestorType=controls:RadioGroup}}" Value="Vertical">
|
||||
<DataTrigger Binding="{Binding Orientation,RelativeSource={RelativeSource AncestorType=controls:ButtonGroup}}" Value="Vertical">
|
||||
<Setter Property="Margin" Value="0,-1,0,0"/>
|
||||
</DataTrigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource BorderBrush}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ButtonBaseBaseStyle.xaml"/>
|
||||
@@ -218,4 +219,53 @@
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0"/>
|
||||
<Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
|
||||
<Setter Property="Padding" Value="10,0"/>
|
||||
<Setter Property="Margin" Value="-1,0,0,0"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border x:Name="BorderRoot" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<ContentPresenter x:Name="contentPresenter" TextElement.Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="TextElement.Foreground" Value="{DynamicResource PrimaryBrush}" TargetName="contentPresenter"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="true">
|
||||
<Setter Property="BorderBrush" Value="{Binding Path=(controls:TitleElement.BorderBrush),RelativeSource={RelativeSource TemplatedParent}}" TargetName="BorderRoot"/>
|
||||
<Setter Property="Background" Value="{Binding Path=(controls:TitleElement.Background),RelativeSource={RelativeSource TemplatedParent}}" TargetName="BorderRoot"/>
|
||||
<Setter Property="TextElement.Foreground" Value="{Binding Path=(controls:TitleElement.Foreground),RelativeSource={RelativeSource TemplatedParent}}" TargetName="contentPresenter"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value="0.4"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Panel.ZIndex" Value="{x:Static system:Int32.MaxValue}"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding Orientation,RelativeSource={RelativeSource AncestorType=controls:ButtonGroup}}" Value="Vertical">
|
||||
<Setter Property="Margin" Value="0,-1,0,0"/>
|
||||
</DataTrigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource BorderBrush}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -81,4 +81,28 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemDefault" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button"/>
|
||||
|
||||
<Style x:Key="ButtonGroupItemHorizontalFirst" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4,0,0,4"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemHorizontalLast" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0,4,4,0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemSingle" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemVerticalFirst" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4,4,0,0"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ButtonGroupItemVerticalLast" BasedOn="{StaticResource ButtonGroupItemBaseStyle}" TargetType="Button">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0,0,4,4"/>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
+3
-3
@@ -3,12 +3,12 @@
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Base/RadioGroupBaseStyle.xaml"/>
|
||||
<ResourceDictionary Source="Base/ButtonGroupBaseStyle.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style BasedOn="{StaticResource RadioGroupBaseStyle}" TargetType="controls:RadioGroup"/>
|
||||
<Style BasedOn="{StaticResource ButtonGroupBaseStyle}" TargetType="controls:ButtonGroup"/>
|
||||
|
||||
<Style x:Key="RadioGroupSolid" BasedOn="{StaticResource RadioGroupBaseStyle}" TargetType="controls:RadioGroup">
|
||||
<Style x:Key="ButtonGroupSolid" BasedOn="{StaticResource ButtonGroupBaseStyle}" TargetType="controls:ButtonGroup">
|
||||
<Setter Property="controls:TitleElement.BorderBrush" Value="{DynamicResource TitleBrush}"/>
|
||||
<Setter Property="controls:TitleElement.Background" Value="{DynamicResource TitleBrush}"/>
|
||||
<Setter Property="controls:TitleElement.Foreground" Value="{DynamicResource TextIconBrush}"/>
|
||||
@@ -49,7 +49,7 @@
|
||||
<ResourceDictionary Source="ToolBar.xaml"/>
|
||||
<ResourceDictionary Source="SearchBar.xaml"/>
|
||||
<ResourceDictionary Source="Tag.xaml"/>
|
||||
<ResourceDictionary Source="RadioGroup.xaml"/>
|
||||
<ResourceDictionary Source="ButtonGroup.xaml"/>
|
||||
<ResourceDictionary Source="FlipClock.xaml"/>
|
||||
<ResourceDictionary Source="Rate.xaml"/>
|
||||
<ResourceDictionary Source="Shield.xaml"/>
|
||||
|
||||
@@ -264,4 +264,28 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemDefault" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton"/>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemHorizontalFirst" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4,0,0,4"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemHorizontalLast" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0,4,4,0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemSingle" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemVerticalFirst" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="4,4,0,0"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ToggleButtonGroupItemVerticalLast" BasedOn="{StaticResource ToggleButtonGroupItemBaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="controls:BorderElement.CornerRadius" Value="0,0,4,4"/>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
public class ButtonGroupItemStyleSelector : StyleSelector
|
||||
{
|
||||
public override Style SelectStyle(object item, DependencyObject container)
|
||||
{
|
||||
if (container is ButtonGroup buttonGroup && item is ButtonBase buttonBase)
|
||||
{
|
||||
var count = buttonGroup.Items.Count;
|
||||
|
||||
switch (buttonBase)
|
||||
{
|
||||
case RadioButton _:
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<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
|
||||
? ResourceToken.RadioGroupItemHorizontalLast
|
||||
: ResourceToken.RadioGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceToken.RadioGroupItemVerticalLast
|
||||
: ResourceToken.RadioGroupItemDefault);
|
||||
}
|
||||
|
||||
case Button _:
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<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
|
||||
? ResourceToken.ButtonGroupItemHorizontalLast
|
||||
: ResourceToken.ButtonGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceToken.ButtonGroupItemVerticalLast
|
||||
: ResourceToken.ButtonGroupItemDefault);
|
||||
}
|
||||
|
||||
case ToggleButton _:
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
return ResourceHelper.GetResource<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
|
||||
? ResourceToken.ToggleButtonGroupItemHorizontalLast
|
||||
: ResourceToken.ToggleButtonGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.ToggleButtonGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceToken.ToggleButtonGroupItemVerticalLast
|
||||
: ResourceToken.ToggleButtonGroupItemDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
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<Style>(ResourceToken.RadioGroupItemSingle);
|
||||
}
|
||||
|
||||
var index = radioGroup.Items.IndexOf(radioButton);
|
||||
return radioGroup.Orientation == Orientation.Horizontal
|
||||
? index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemHorizontalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceToken.RadioGroupItemHorizontalLast
|
||||
: ResourceToken.RadioGroupItemDefault)
|
||||
: index == 0
|
||||
? ResourceHelper.GetResource<Style>(ResourceToken.RadioGroupItemVerticalFirst)
|
||||
: ResourceHelper.GetResource<Style>(index == count - 1
|
||||
? ResourceToken.RadioGroupItemVerticalLast
|
||||
: ResourceToken.RadioGroupItemDefault);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user