Skip to content

Commit 915cd79

Browse files
committed
Merge pull request #195 from xaviergonz/patch-2
Fix for MaterialDesignFlatToggleButton
2 parents b9ec6f7 + 85ce7dd commit 915cd79

File tree

1 file changed

+53
-54
lines changed

1 file changed

+53
-54
lines changed

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ToggleButton.xaml

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
<Setter Property="Foreground" Value="{DynamicResource SecondaryAccentForegroundBrush}"/>
178178
</Style>
179179

180-
<Style x:Key="MaterialDesignFlatToggleButton" TargetType="{x:Type ToggleButton}">
180+
<Style x:Key="MaterialDesignFlatToggleButton" TargetType="{x:Type ToggleButton}">
181181
<Setter Property="Foreground" Value="#616161"/>
182182
<Setter Property="Background" Value="#e0e0e0"/>
183183
<Setter Property="Width" Value="40"/>
@@ -189,82 +189,81 @@
189189
<Setter Property="Template">
190190
<Setter.Value>
191191
<ControlTemplate TargetType="{x:Type ToggleButton}">
192-
<Grid Clip="{Binding ElementName=UncheckedEllipse, Path=RenderedGeometry}" ClipToBounds="True">
192+
<Grid ClipToBounds="True" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
193193
<VisualStateManager.VisualStateGroups>
194194
<VisualStateGroup x:Name="CommonStates">
195195
<VisualState x:Name="Normal"/>
196196
<VisualState x:Name="Disabled">
197197
<Storyboard>
198198
<DoubleAnimation Duration="0" To="0.23" Storyboard.TargetProperty="(UIElement.Opacity)" />
199199
</Storyboard>
200-
</VisualState>
200+
</VisualState>
201201
</VisualStateGroup>
202202
<VisualStateGroup x:Name="CheckStates">
203-
<VisualStateGroup.Transitions>
204-
<VisualTransition From="*" To="Checked">
205-
<Storyboard>
206-
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="(Control.Width)" Storyboard.TargetName="CheckedEllipse">
207-
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.0" />
208-
<LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.1" />
209-
</DoubleAnimationUsingKeyFrames>
210-
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="(Control.Height)" Storyboard.TargetName="CheckedEllipse">
211-
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.0" />
212-
<LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.1" />
213-
</DoubleAnimationUsingKeyFrames>
214-
</Storyboard>
215-
</VisualTransition>
216-
<VisualTransition From="Checked" To="Unchecked">
217-
<Storyboard>
218-
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="(Control.Width)" Storyboard.TargetName="CheckedEllipse">
219-
<LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.0" />
220-
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.1" />
221-
</DoubleAnimationUsingKeyFrames>
222-
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="(Control.Height)" Storyboard.TargetName="CheckedEllipse">
223-
<LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.0" />
224-
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.1" />
225-
</DoubleAnimationUsingKeyFrames>
226-
</Storyboard>
227-
</VisualTransition>
228-
</VisualStateGroup.Transitions>
203+
<VisualStateGroup.Transitions>
204+
<VisualTransition From="*" To="Checked">
205+
<Storyboard>
206+
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="CheckedEllipseScale">
207+
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.0" />
208+
<LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:0.1" />
209+
</DoubleAnimationUsingKeyFrames>
210+
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="CheckedEllipseScale">
211+
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.0" />
212+
<LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:0.1" />
213+
</DoubleAnimationUsingKeyFrames>
214+
</Storyboard>
215+
</VisualTransition>
216+
<VisualTransition From="Checked" To="Unchecked">
217+
<Storyboard>
218+
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="CheckedEllipseScale">
219+
<LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:0.0" />
220+
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.1" />
221+
</DoubleAnimationUsingKeyFrames>
222+
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="CheckedEllipseScale">
223+
<LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:0.0" />
224+
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.1" />
225+
</DoubleAnimationUsingKeyFrames>
226+
</Storyboard>
227+
</VisualTransition>
228+
</VisualStateGroup.Transitions>
229229
<VisualState x:Name="Checked">
230230
<Storyboard>
231-
<DoubleAnimation Duration="0" Storyboard.TargetProperty="(Control.Width)" Storyboard.TargetName="CheckedEllipse"
232-
To="40" />
233-
<DoubleAnimation Duration="0" Storyboard.TargetProperty="(Control.Height)" Storyboard.TargetName="CheckedEllipse"
234-
To="40" />
231+
<DoubleAnimation Duration="0" Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="CheckedEllipseScale" To="1.0" />
232+
<DoubleAnimation Duration="0" Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="CheckedEllipseScale" To="1.0" />
235233
</Storyboard>
236234
</VisualState>
237235
<VisualState x:Name="Unchecked">
238236
<Storyboard>
239-
<DoubleAnimation Duration="0" Storyboard.TargetProperty="(Control.Width)" Storyboard.TargetName="CheckedEllipse"
240-
To="0" />
241-
<DoubleAnimation Duration="0" Storyboard.TargetProperty="(Control.Height)" Storyboard.TargetName="CheckedEllipse"
242-
To="0" />
237+
<DoubleAnimation Duration="0" Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="CheckedEllipseScale" To="0" />
238+
<DoubleAnimation Duration="0" Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="CheckedEllipseScale" To="0" />
243239
</Storyboard>
244240
</VisualState>
245241
</VisualStateGroup>
246242
</VisualStateManager.VisualStateGroups>
247-
<Ellipse Fill="Transparent" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="HoverEllipse"
248-
Stroke="Transparent" StrokeThickness="1" />
249-
<Ellipse Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="CheckedEllipse" />
243+
<Ellipse Fill="Transparent" x:Name="HoverEllipse" Stroke="Transparent" StrokeThickness="1" />
244+
<Ellipse Fill="{TemplateBinding Background}" x:Name="CheckedEllipse" RenderTransformOrigin="0.5, 0.5">
245+
<Ellipse.RenderTransform>
246+
<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.0" ScaleY="1.0" x:Name="CheckedEllipseScale"/>
247+
</Ellipse.RenderTransform>
248+
</Ellipse>
250249
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
251250
</Grid>
252251
<ControlTemplate.Triggers>
253-
<Trigger Property="IsMouseOver" Value="true">
254-
<Setter Property="Stroke" TargetName="HoverEllipse" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
252+
<Trigger Property="IsMouseOver" Value="true">
253+
<Setter Property="Stroke" TargetName="HoverEllipse" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
254+
</Trigger>
255+
<!-- TODO
256+
<Trigger Property="IsFocused" Value="True">
257+
<Setter Property="BorderBrush" TargetName="normal" Value="{Binding (Custom:ControlsHelper.FocusBorderBrush), RelativeSource={RelativeSource TemplatedParent}}"/>
255258
</Trigger>
256-
<!-- TODO
257-
<Trigger Property="IsFocused" Value="True">
258-
<Setter Property="BorderBrush" TargetName="normal" Value="{Binding (Custom:ControlsHelper.FocusBorderBrush), RelativeSource={RelativeSource TemplatedParent}}"/>
259-
</Trigger>
260-
-->
261-
</ControlTemplate.Triggers>
262-
</ControlTemplate>
263-
</Setter.Value>
259+
-->
260+
</ControlTemplate.Triggers>
261+
</ControlTemplate>
262+
</Setter.Value>
264263
</Setter>
265-
</Style>
266-
267-
<Style x:Key="MaterialDesignFlatPrimaryToggleButton" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
264+
</Style>
265+
266+
<Style x:Key="MaterialDesignFlatPrimaryToggleButton" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
268267
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"/>
269268
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueDarkBrush}"/>
270269
</Style>
@@ -576,4 +575,4 @@
576575
</Setter>
577576
</Style>
578577

579-
</ResourceDictionary>
578+
</ResourceDictionary>

0 commit comments

Comments
 (0)