月更
This commit is contained in:
61
AntDesignWPF/Controls/RadioButtonGroup/RadioButtonGroup.cs
Normal file
61
AntDesignWPF/Controls/RadioButtonGroup/RadioButtonGroup.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace AntDesignWPF.Controls
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
public class RadioButtonGroup : ItemsControl
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public static readonly DependencyProperty SizeProperty =
|
||||
DependencyProperty.Register("Size", typeof(Sizes?), typeof(RadioButtonGroup), new PropertyMetadata(null));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets size for radio button style
|
||||
/// </summary>
|
||||
public Sizes? Size
|
||||
{
|
||||
get { return (Sizes?)GetValue(SizeProperty); }
|
||||
set { SetValue(SizeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OrientationProperty =
|
||||
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(RadioButtonGroup), new PropertyMetadata(Orientation.Horizontal));
|
||||
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get { return (Orientation)GetValue(OrientationProperty); }
|
||||
set { SetValue(OrientationProperty, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static RadioButtonGroup()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(RadioButtonGroup), new FrameworkPropertyMetadata(typeof(RadioButtonGroup)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
base.OnItemsChanged(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class RadioButtonGroupTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
||||
{
|
||||
return base.SelectTemplate(item, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
AntDesignWPF/Controls/RadioButtonGroup/RadioButtonGroup.xaml
Normal file
38
AntDesignWPF/Controls/RadioButtonGroup/RadioButtonGroup.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:controls="clr-namespace:AntDesignWPF.Controls"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<controls:RadioButtonGroupTemplateSelector x:Key="RadioButtonGroupTemplateSelector" />
|
||||
|
||||
<Style TargetType="{x:Type controls:RadioButtonGroup}">
|
||||
<Setter Property="Orientation" Value="Horizontal" />
|
||||
<!--<Setter Property="ItemTemplateSelector" Value="{StaticResource RadioButtonGroupTemplateSelector}" />-->
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:RadioButtonGroup}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<ItemsPresenter />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<!--<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<RadioButton Content="{Binding Label, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>-->
|
||||
<Setter Property="ItemsPanel">
|
||||
<Setter.Value>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="{Binding Orientation, RelativeSource={RelativeSource AncestorType={x:Type controls:RadioButtonGroup}}}" />
|
||||
</ItemsPanelTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user