Skip to content

Commit c600683

Browse files
mzy666888Keboo
andauthored
RadioButton 添加自定义大小功能 (#3726)
* RadioButton 添加自定义大小功能 * Adding sample to normal WPF demo app as well --------- Co-authored-by: Kevin Bost <[email protected]>
1 parent e95413f commit c600683

File tree

4 files changed

+39
-88
lines changed

4 files changed

+39
-88
lines changed

src/MainDemo.Wpf/Toggles.xaml

Lines changed: 7 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@
214214
IsChecked="True"
215215
Style="{StaticResource MaterialDesignSecondaryRadioButton}" />
216216
</smtx:XamlDisplay>
217+
218+
219+
<smtx:XamlDisplay Margin="0,5,8,8"
220+
VerticalAlignment="Center"
221+
UniqueKey="toggle_buttons_radio_button_large">
222+
<RadioButton Content="Custom RadioButton Size" materialDesign:RadioButtonAssist.RadioButtonSize="40" />
223+
</smtx:XamlDisplay>
217224
</WrapPanel>
218225

219226
<Rectangle Style="{StaticResource PageSectionSeparator}" />
@@ -270,31 +277,6 @@
270277
</smtx:XamlDisplay>
271278
</WrapPanel>
272279

273-
<smtx:XamlDisplay Margin="0,0,0,8" UniqueKey="checkboxes_1">
274-
<StackPanel>
275-
<CheckBox Content="Checked" IsChecked="True" />
276-
277-
<CheckBox Content="Unchecked" IsChecked="False" />
278-
279-
<CheckBox Content="Indeterminate" IsChecked="{x:Null}" />
280-
281-
<CheckBox Content="Disabled Checked"
282-
IsChecked="True"
283-
IsEnabled="False" />
284-
<CheckBox Content="Disabled Checked"
285-
IsChecked="True"
286-
IsEnabled="False" />
287-
288-
<CheckBox Content="Disabled Unchecked"
289-
IsChecked="False"
290-
IsEnabled="False" />
291-
292-
<CheckBox Content="Disabled Indeterminate"
293-
IsChecked="{x:Null}"
294-
IsEnabled="False" />
295-
</StackPanel>
296-
</smtx:XamlDisplay>
297-
298280
<smtx:XamlDisplay UniqueKey="checkboxes_2">
299281
<StackPanel>
300282
<CheckBox Margin="0,0,0,8"
@@ -307,8 +289,6 @@
307289
</StackPanel>
308290
</smtx:XamlDisplay>
309291

310-
311-
312292
<Rectangle Style="{StaticResource PageSectionSeparator}" />
313293
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Switch" />
314294

@@ -472,64 +452,6 @@
472452
</ListBox>
473453
</smtx:XamlDisplay>
474454

475-
476-
<Border Grid.Row="6"
477-
Grid.Column="0"
478-
Grid.ColumnSpan="2"
479-
Margin="0,24,0,0"
480-
BorderBrush="{DynamicResource MaterialDesignDivider}"
481-
BorderThickness="0,1,0,0" />
482-
483-
<TextBlock Grid.Row="7"
484-
Grid.Column="0"
485-
Margin="0,24"
486-
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
487-
Text="Checkboxes" />
488-
489-
<smtx:XamlDisplay Grid.Row="8"
490-
Grid.Column="0"
491-
HorizontalAlignment="Left"
492-
UniqueKey="checkboxes_3">
493-
<StackPanel Margin="8,0">
494-
<CheckBox Content="Checked" IsChecked="True" />
495-
496-
<CheckBox Content="Unchecked" IsChecked="False" />
497-
498-
<CheckBox Content="Indeterminate" IsChecked="{x:Null}" />
499-
500-
<CheckBox Content="Disabled Checked"
501-
IsChecked="True"
502-
IsEnabled="False" />
503-
<CheckBox Content="Disabled Checked"
504-
IsChecked="True"
505-
IsEnabled="False" />
506-
507-
<CheckBox Content="Disabled Unchecked"
508-
IsChecked="False"
509-
IsEnabled="False" />
510-
511-
<CheckBox Content="Disabled Indeterminate"
512-
IsChecked="{x:Null}"
513-
IsEnabled="False" />
514-
</StackPanel>
515-
</smtx:XamlDisplay>
516-
517-
<smtx:XamlDisplay Grid.Row="8"
518-
Grid.Column="1"
519-
HorizontalAlignment="Left"
520-
VerticalAlignment="Top"
521-
UniqueKey="checkboxes_4">
522-
<StackPanel Margin="8,0">
523-
<CheckBox materialDesign:CheckBoxAssist.CheckBoxSize="30"
524-
Content="Custom Size"
525-
IsChecked="True" />
526-
<CheckBox materialDesign:RippleAssist.IsDisabled="True"
527-
Content="Ripple disabled"
528-
IsChecked="True" />
529-
</StackPanel>
530-
</smtx:XamlDisplay>
531-
532-
533455
<Rectangle Style="{StaticResource PageSectionSeparator}" />
534456
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Tabs" />
535457

src/MaterialDesign3.Demo.Wpf/Toggles.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
<RadioButton Content="Ga Ga" Style="{StaticResource MaterialDesignRadioButton}" />
117117
</smtx:XamlDisplay>
118118

119+
<smtx:XamlDisplay Margin="0,5,8,8"
120+
VerticalAlignment="Center"
121+
UniqueKey="buttons_42221">
122+
<RadioButton Content="Custom RadioButton Size" materialDesign:RadioButtonAssist.RadioButtonSize="40" Style="{StaticResource MaterialDesignRadioButton}" />
123+
</smtx:XamlDisplay>
124+
119125
<smtx:XamlDisplay Margin="0,5,8,8"
120126
VerticalAlignment="Center"
121127
UniqueKey="buttons_42">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace MaterialDesignThemes.Wpf
2+
{
3+
public class RadioButtonAssist
4+
{
5+
private const double DefaultRadioButtonSize = 18.0;
6+
7+
#region AttachedProperty : RadioButtonSizeProperty
8+
public static readonly DependencyProperty RadioButtonSizeProperty =
9+
DependencyProperty.RegisterAttached(
10+
"RadioButtonSize",
11+
typeof(double),
12+
typeof(RadioButtonAssist),
13+
new PropertyMetadata(DefaultRadioButtonSize)
14+
);
15+
16+
public static double GetRadioButtonSize(RadioButton element) =>
17+
(double)element.GetValue(RadioButtonSizeProperty);
18+
19+
public static void SetRadioButtonSize(RadioButton element, double checkBoxSize) =>
20+
element.SetValue(RadioButtonSizeProperty, checkBoxSize);
21+
#endregion
22+
}
23+
}

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RadioButton.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
<ColumnDefinition Width="Auto" />
7979
<ColumnDefinition Width="*" />
8080
</Grid.ColumnDefinitions>
81-
<Viewbox Width="18"
82-
Height="18"
83-
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
81+
<Viewbox Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:RadioButtonAssist.RadioButtonSize)}"
82+
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:RadioButtonAssist.RadioButtonSize)}"
83+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
8484
<Canvas Width="24" Height="24">
8585
<Path x:Name="Graphic"
8686
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"

0 commit comments

Comments
 (0)