Skip to content

Commit 816d1eb

Browse files
Add fallback value to binding to avoid division by NaN
The bound value can become NaN when the control is Unloaded. To avoid exceptions, I simply apply a fallback value of 0.
1 parent 9ba36d8 commit 816d1eb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/MaterialDesignThemes.Wpf/Themes/MaterialDesign3.ToggleButton.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@
377377
</DoubleAnimation>
378378
<DoubleAnimation Storyboard.TargetName="Thumb"
379379
Storyboard.TargetProperty="Width"
380-
To="{Binding Tag, ElementName=SwitchGrid}"
380+
To="{Binding Tag, ElementName=SwitchGrid, FallbackValue=0}"
381381
Duration="0:0:0.2">
382382
<DoubleAnimation.EasingFunction>
383383
<QuadraticEase EasingMode="EaseOut" />
384384
</DoubleAnimation.EasingFunction>
385385
</DoubleAnimation>
386386
<DoubleAnimation Storyboard.TargetName="Thumb"
387387
Storyboard.TargetProperty="Height"
388-
To="{Binding Tag, ElementName=SwitchGrid}"
388+
To="{Binding Tag, ElementName=SwitchGrid, FallbackValue=0}"
389389
Duration="0:0:0.16">
390390
<DoubleAnimation.EasingFunction>
391391
<QuadraticEase EasingMode="EaseOut" />
@@ -399,11 +399,11 @@
399399
Duration="0" />
400400
<DoubleAnimation Storyboard.TargetName="Thumb"
401401
Storyboard.TargetProperty="Width"
402-
To="{Binding Tag, ElementName=SwitchGrid}"
402+
To="{Binding Tag, ElementName=SwitchGrid, FallbackValue=0}"
403403
Duration="0" />
404404
<DoubleAnimation Storyboard.TargetName="Thumb"
405405
Storyboard.TargetProperty="Height"
406-
To="{Binding Tag, ElementName=SwitchGrid}"
406+
To="{Binding Tag, ElementName=SwitchGrid, FallbackValue=0}"
407407
Duration="0" />
408408
</Storyboard>
409409
</Grid.Resources>

0 commit comments

Comments
 (0)