Skip to content

Commit b27aafb

Browse files
committed
move dialog popup IsOpen animation into code; WPF throwing sporadic errors. re. issue #545
1 parent e38fa72 commit b27aafb

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Data;
1010
using System.Windows.Input;
1111
using System.Windows.Threading;
12+
using ControlzEx;
1213
using MaterialDesignThemes.Wpf.Transitions;
1314

1415
namespace MaterialDesignThemes.Wpf
@@ -246,6 +247,7 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
246247

247248
if (dialogHost.IsOpen)
248249
{
250+
dialogHost._popup.SetCurrentValue(Popup.IsOpenProperty, true);
249251
WatchWindowActivation(dialogHost);
250252
dialogHost._currentSnackbarMessageQueueUnPauseAction = dialogHost.SnackbarMessageQueue?.Pause();
251253
}
@@ -266,7 +268,13 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
266268
// if the MainWindow has started up minimized. Even when Show() has been called, this doesn't
267269
// seem to have been set.
268270

269-
dialogHost.Dispatcher.InvokeAsync(() => dialogHost._restoreFocusDialogClose?.Focus(), DispatcherPriority.Input);
271+
//close popup in code (previously was in a storyboard)....WPF was throwing sporadic errors in some cases
272+
273+
Task.Delay(TimeSpan.FromMilliseconds(300)).ContinueWith(t =>
274+
{
275+
dialogHost._popup.SetCurrentValue(Popup.IsOpenProperty, false);
276+
dialogHost._restoreFocusDialogClose?.Focus();
277+
}, TaskScheduler.FromCurrentSynchronizationContext());
270278

271279
return;
272280
}
@@ -424,7 +432,7 @@ public override void OnApplyTemplate()
424432
_contentCoverGrid.MouseLeftButtonUp += ContentCoverGridOnMouseLeftButtonUp;
425433

426434
VisualStateManager.GoToState(this, SelectState(), false);
427-
435+
428436
base.OnApplyTemplate();
429437
}
430438

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,6 @@
483483
<VisualStateGroup.Transitions>
484484
<VisualTransition From="Closed" To="Open">
485485
<Storyboard>
486-
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
487-
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
488-
</BooleanAnimationUsingKeyFrames>
489486
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
490487
<EasingDoubleKeyFrame Value="0" KeyTime="0" />
491488
<EasingDoubleKeyFrame Value="0.56" KeyTime="0:0:0.3">
@@ -522,10 +519,6 @@
522519
</VisualTransition>
523520
<VisualTransition From="Open" To="Closed">
524521
<Storyboard>
525-
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
526-
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
527-
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0.3" />
528-
</BooleanAnimationUsingKeyFrames>
529522
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
530523
<EasingDoubleKeyFrame Value="0.56" KeyTime="0" />
531524
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.3">
@@ -566,9 +559,6 @@
566559
</VisualStateGroup.Transitions>
567560
<VisualState x:Name="Open">
568561
<Storyboard>
569-
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
570-
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
571-
</BooleanAnimationUsingKeyFrames>
572562
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
573563
Duration="0"
574564
To=".56" />
@@ -584,12 +574,7 @@
584574
</Storyboard>
585575
</VisualState>
586576
<VisualState x:Name="Closed">
587-
<Storyboard>
588-
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
589-
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
590-
<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0.3" />
591-
</BooleanAnimationUsingKeyFrames>
592-
</Storyboard>
577+
<Storyboard />
593578
</VisualState>
594579
</VisualStateGroup>
595580
</VisualStateManager.VisualStateGroups>

0 commit comments

Comments
 (0)