Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioButton 添加自定义大小功能 #3726

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 7 additions & 85 deletions src/MainDemo.Wpf/Toggles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
IsChecked="True"
Style="{StaticResource MaterialDesignSecondaryRadioButton}" />
</smtx:XamlDisplay>


<smtx:XamlDisplay Margin="0,5,8,8"
VerticalAlignment="Center"
UniqueKey="toggle_buttons_radio_button_large">
<RadioButton Content="Custom RadioButton Size" materialDesign:RadioButtonAssist.RadioButtonSize="40" />
</smtx:XamlDisplay>
</WrapPanel>

<Rectangle Style="{StaticResource PageSectionSeparator}" />
Expand Down Expand Up @@ -270,31 +277,6 @@
</smtx:XamlDisplay>
</WrapPanel>

<smtx:XamlDisplay Margin="0,0,0,8" UniqueKey="checkboxes_1">
<StackPanel>
<CheckBox Content="Checked" IsChecked="True" />

<CheckBox Content="Unchecked" IsChecked="False" />

<CheckBox Content="Indeterminate" IsChecked="{x:Null}" />

<CheckBox Content="Disabled Checked"
IsChecked="True"
IsEnabled="False" />
<CheckBox Content="Disabled Checked"
IsChecked="True"
IsEnabled="False" />

<CheckBox Content="Disabled Unchecked"
IsChecked="False"
IsEnabled="False" />

<CheckBox Content="Disabled Indeterminate"
IsChecked="{x:Null}"
IsEnabled="False" />
</StackPanel>
</smtx:XamlDisplay>

<smtx:XamlDisplay UniqueKey="checkboxes_2">
<StackPanel>
<CheckBox Margin="0,0,0,8"
Expand All @@ -307,8 +289,6 @@
</StackPanel>
</smtx:XamlDisplay>



<Rectangle Style="{StaticResource PageSectionSeparator}" />
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Switch" />

Expand Down Expand Up @@ -472,64 +452,6 @@
</ListBox>
</smtx:XamlDisplay>


<Border Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,24,0,0"
BorderBrush="{DynamicResource MaterialDesignDivider}"
BorderThickness="0,1,0,0" />

<TextBlock Grid.Row="7"
Grid.Column="0"
Margin="0,24"
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="Checkboxes" />

<smtx:XamlDisplay Grid.Row="8"
Grid.Column="0"
HorizontalAlignment="Left"
UniqueKey="checkboxes_3">
<StackPanel Margin="8,0">
<CheckBox Content="Checked" IsChecked="True" />

<CheckBox Content="Unchecked" IsChecked="False" />

<CheckBox Content="Indeterminate" IsChecked="{x:Null}" />

<CheckBox Content="Disabled Checked"
IsChecked="True"
IsEnabled="False" />
<CheckBox Content="Disabled Checked"
IsChecked="True"
IsEnabled="False" />

<CheckBox Content="Disabled Unchecked"
IsChecked="False"
IsEnabled="False" />

<CheckBox Content="Disabled Indeterminate"
IsChecked="{x:Null}"
IsEnabled="False" />
</StackPanel>
</smtx:XamlDisplay>

<smtx:XamlDisplay Grid.Row="8"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
UniqueKey="checkboxes_4">
<StackPanel Margin="8,0">
<CheckBox materialDesign:CheckBoxAssist.CheckBoxSize="30"
Content="Custom Size"
IsChecked="True" />
<CheckBox materialDesign:RippleAssist.IsDisabled="True"
Content="Ripple disabled"
IsChecked="True" />
</StackPanel>
</smtx:XamlDisplay>


<Rectangle Style="{StaticResource PageSectionSeparator}" />
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Tabs" />

Expand Down
6 changes: 6 additions & 0 deletions src/MaterialDesign3.Demo.Wpf/Toggles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<RadioButton Content="Ga Ga" Style="{StaticResource MaterialDesignRadioButton}" />
</smtx:XamlDisplay>

<smtx:XamlDisplay Margin="0,5,8,8"
VerticalAlignment="Center"
UniqueKey="buttons_42221">
<RadioButton Content="Custom RadioButton Size" materialDesign:RadioButtonAssist.RadioButtonSize="40" Style="{StaticResource MaterialDesignRadioButton}" />
</smtx:XamlDisplay>

<smtx:XamlDisplay Margin="0,5,8,8"
VerticalAlignment="Center"
UniqueKey="buttons_42">
Expand Down
23 changes: 23 additions & 0 deletions src/MaterialDesignThemes.Wpf/RadioButtonAssist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace MaterialDesignThemes.Wpf
{
public class RadioButtonAssist
{
private const double DefaultRadioButtonSize = 18.0;

#region AttachedProperty : RadioButtonSizeProperty
public static readonly DependencyProperty RadioButtonSizeProperty =
DependencyProperty.RegisterAttached(
"RadioButtonSize",
typeof(double),
typeof(RadioButtonAssist),
new PropertyMetadata(DefaultRadioButtonSize)
);

public static double GetRadioButtonSize(RadioButton element) =>
(double)element.GetValue(RadioButtonSizeProperty);

public static void SetRadioButtonSize(RadioButton element, double checkBoxSize) =>
element.SetValue(RadioButtonSizeProperty, checkBoxSize);
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Viewbox Width="18"
Height="18"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Viewbox Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:RadioButtonAssist.RadioButtonSize)}"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:RadioButtonAssist.RadioButtonSize)}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Canvas Width="24" Height="24">
<Path x:Name="Graphic"
Data="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"
Expand Down
Loading