Skip to content

Commit 1ad50f7

Browse files
committed
Merge branch 'issue370' of https://github.com/Keboo/MaterialDesignInXamlToolkit into Keboo-issue370
2 parents 8257e94 + 346ab25 commit 1ad50f7

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:system="clr-namespace:System;assembly=mscorlib"
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
88
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
9+
xmlns:domain="clr-namespace:MaterialDesignDemo.Domain"
910
mc:Ignorable="d"
1011
d:DesignHeight="500" d:DesignWidth="800">
1112
<UserControl.Resources>
@@ -254,7 +255,14 @@
254255
</ToggleButton>
255256
</StackPanel>
256257
<StackPanel Grid.Row="1" Margin="0 16 0 0" Orientation="Horizontal">
257-
<RadioButton Style="{StaticResource MaterialDesignRadioButton}" Margin="0 0 8 8" VerticalAlignment="Center" IsChecked="True">
258+
<RadioButton Style="{StaticResource MaterialDesignRadioButton}" Margin="0 0 8 8" VerticalAlignment="Center" Tag="True">
259+
<RadioButton.IsChecked>
260+
<Binding Path="Tag" RelativeSource="{RelativeSource Self}">
261+
<Binding.ValidationRules>
262+
<domain:IsCheckedValidationRule />
263+
</Binding.ValidationRules>
264+
</Binding>
265+
</RadioButton.IsChecked>
258266
Radio
259267
</RadioButton>
260268
<RadioButton Style="{StaticResource MaterialDesignRadioButton}" Margin="0 0 8 8" VerticalAlignment="Center">
@@ -267,15 +275,22 @@
267275
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="0 0 8 8" VerticalAlignment="Center">
268276
Check
269277
</CheckBox>
270-
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="0 0 8 8" VerticalAlignment="Center" IsChecked="True">
278+
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="0 0 8 8" VerticalAlignment="Center" Tag="True">
279+
<CheckBox.IsChecked>
280+
<Binding Path="Tag" RelativeSource="{RelativeSource Self}">
281+
<Binding.ValidationRules>
282+
<domain:IsCheckedValidationRule />
283+
</Binding.ValidationRules>
284+
</Binding>
285+
</CheckBox.IsChecked>
271286
Mate
272287
</CheckBox>
273288
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="0 0 8 8" VerticalAlignment="Center"
274289
IsEnabled="False" IsChecked="True">
275290
Disabled
276291
</CheckBox>
277292
</StackPanel>
278-
<StackPanel Grid.Row="2" Margin="0 16 0 0" Orientation="Horizontal">
293+
<StackPanel Grid.Row="2" Margin="0 16 0 0" Orientation="Horizontal">
279294
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" VerticalAlignment="Center"
280295
ToolTip="Default ToggleButton Style"/>
281296
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" VerticalAlignment="Center" Margin="8 0 0 0" IsEnabled="False" />
@@ -299,7 +314,7 @@
299314
</materialDesign:ToggleButtonAssist.OnContent>
300315
</ToggleButton>
301316
</StackPanel>
302-
<StackPanel Grid.Row="3" Margin="0 16 0 0" Orientation="Horizontal">
317+
<StackPanel Grid.Row="3" Margin="0 16 0 0" Orientation="Horizontal">
303318
<ToggleButton Style="{StaticResource MaterialDesignFlatToggleButton}" ToolTip="MaterialDesignFlatToggleButton">
304319
<materialDesign:PackIcon Kind="Paperclip" Height="21" Width="21" />
305320
</ToggleButton>
@@ -338,7 +353,7 @@
338353
<materialDesign:PackIcon Kind="FormatAlignJustify"/>
339354
</ListBoxItem>
340355
</ListBox>
341-
<ListBox Grid.Column="1" Grid.Row="2" SelectionMode="Extended" Style="{StaticResource MaterialDesignToolToggleFlatListBox}">
356+
<ListBox Grid.Column="1" Grid.Row="2" SelectionMode="Extended" Style="{StaticResource MaterialDesignToolToggleFlatListBox}">
342357
<ListBox.ToolTip>
343358
<StackPanel>
344359
<TextBlock Text="MaterialDesignToolToggleListBox" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Controls;
4+
5+
namespace MaterialDesignDemo.Domain
6+
{
7+
public class IsCheckedValidationRule : ValidationRule
8+
{
9+
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
10+
{
11+
if( value is bool && (bool) value)
12+
{
13+
return ValidationResult.ValidResult;
14+
}
15+
return new ValidationResult(false, "Option must be checked");
16+
}
17+
}
18+
}

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
</Compile>
9494
<Compile Include="Domain\DocumentationLinkType.cs" />
9595
<Compile Include="Domain\FutureDateValidationRule.cs" />
96+
<Compile Include="Domain\IsCheckedValidationRule.cs" />
9697
<Compile Include="Domain\MainWindowViewModel.cs" />
9798
<Compile Include="Domain\NotEmptyValidationRule.cs" />
9899
<Compile Include="Domain\NotifyPropertyChangedExtension.cs" />

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.CheckBox.xaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
33

44
<ResourceDictionary.MergedDictionaries>
5-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
5+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
6+
<ResourceDictionary Source="MaterialDesignTheme.ValidationErrorTemplate.xaml" />
67
</ResourceDictionary.MergedDictionaries>
78

89
<Style x:Key="FocusVisual">
@@ -51,6 +52,7 @@
5152
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/>
5253
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
5354
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
55+
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
5456
<Setter Property="Template">
5557
<Setter.Value>
5658
<ControlTemplate TargetType="{x:Type CheckBox}">
@@ -125,6 +127,10 @@
125127
<Setter Property="Data" TargetName="Graphic" Value="M10,17L5,12L6.41,10.58L10,14.17L17.59,6.58L19,8M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z" />
126128
<Setter Property="Opacity" TargetName="Graphic" Value="0.56"/>
127129
</Trigger>
130+
<Trigger Property="Validation.HasError" Value="true">
131+
<Setter Property="Fill" TargetName="Graphic" Value="{DynamicResource ValidationErrorBrush}" />
132+
<Setter Property="Control.Foreground" TargetName="contentPresenter" Value="{DynamicResource ValidationErrorBrush}" />
133+
</Trigger>
128134
</ControlTemplate.Triggers>
129135
</ControlTemplate>
130136
</Setter.Value>
@@ -153,6 +159,7 @@
153159
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
154160
<Setter Property="BorderThickness" Value="1"/>
155161
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
162+
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
156163
<Setter Property="Template">
157164
<Setter.Value>
158165
<ControlTemplate TargetType="{x:Type CheckBox}">
@@ -223,6 +230,10 @@
223230
<Setter Property="Data" TargetName="Graphic" Value="M10,17L5,12L6.41,10.58L10,14.17L17.59,6.58L19,8M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z" />
224231
<Setter Property="Opacity" TargetName="Graphic" Value="0.56"/>
225232
</Trigger>
233+
<Trigger Property="Validation.HasError" Value="true">
234+
<Setter Property="Fill" TargetName="Graphic" Value="{DynamicResource ValidationErrorBrush}" />
235+
<Setter Property="Control.Foreground" TargetName="contentPresenter" Value="{DynamicResource ValidationErrorBrush}" />
236+
</Trigger>
226237
</ControlTemplate.Triggers>
227238
</ControlTemplate>
228239
</Setter.Value>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RadioButton.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
<ResourceDictionary.MergedDictionaries>
4+
<ResourceDictionary Source="MaterialDesignTheme.ValidationErrorTemplate.xaml" />
5+
</ResourceDictionary.MergedDictionaries>
6+
37
<Style x:Key="OptionMarkFocusVisual">
48
<Setter Property="Control.Template">
59
<Setter.Value>
@@ -24,6 +28,7 @@
2428
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
2529
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/>
2630
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
31+
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
2732
<Setter Property="Template">
2833
<Setter.Value>
2934
<ControlTemplate TargetType="{x:Type RadioButton}">
@@ -96,6 +101,10 @@
96101
<Setter Property="Data" TargetName="Graphic" Value="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,2M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7Z" />
97102
<Setter Property="Opacity" TargetName="Graphic" Value="0.56"/>
98103
</Trigger>
104+
<Trigger Property="Validation.HasError" Value="true">
105+
<Setter Property="Fill" TargetName="Graphic" Value="{DynamicResource ValidationErrorBrush}" />
106+
<Setter Property="Control.Foreground" TargetName="contentPresenter" Value="{DynamicResource ValidationErrorBrush}" />
107+
</Trigger>
99108
</ControlTemplate.Triggers>
100109
</ControlTemplate>
101110
</Setter.Value>

0 commit comments

Comments
 (0)