Skip to content

Commit 55d8d11

Browse files
authored
Merge pull request #22 from ButchersBoy/master
update from original repo
2 parents 5ac5e2a + d238ea0 commit 55d8d11

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public class DialogHost : ContentControl
6969
private DialogOpenedEventHandler _attachedDialogOpenedEventHandler;
7070
private DialogClosingEventHandler _attachedDialogClosingEventHandler;
7171
private object _closeDialogExecutionParameter;
72-
private IInputElement _restoreFocus;
72+
private IInputElement _restoreFocusDialogClose;
73+
private IInputElement _restoreFocusWindowReactivation;
7374
private Action _currentSnackbarMessageQueueUnPauseAction = null;
7475
private Action _closeCleanUp = () => { };
7576

@@ -237,8 +238,8 @@ public object Identifier
237238

238239
private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
239240
{
240-
var dialogHost = (DialogHost)dependencyObject;
241-
241+
var dialogHost = (DialogHost)dependencyObject;
242+
242243
if (dialogHost._popupContentControl != null)
243244
ValidationAssist.SetSuppress(dialogHost._popupContentControl, !dialogHost.IsOpen);
244245
VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost));
@@ -260,12 +261,15 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
260261
dialogHost._session.IsEnded = true;
261262
dialogHost._session = null;
262263
dialogHost._closeCleanUp();
263-
264+
dialogHost.Dispatcher.InvokeAsync(() => dialogHost._restoreFocusDialogClose.Focus(), DispatcherPriority.Input);
265+
264266
return;
265267
}
266268

267269
dialogHost._asyncShowWaitHandle.Reset();
268270
dialogHost._session = new DialogSession(dialogHost);
271+
var window = Window.GetWindow(dialogHost);
272+
dialogHost._restoreFocusDialogClose = window != null ? FocusManager.GetFocusedElement(window) : null;
269273

270274
//multiple ways of calling back that the dialog has opened:
271275
// * routed event
@@ -507,7 +511,7 @@ public static DialogClosingEventHandler GetDialogClosingAttached(DependencyObjec
507511
}
508512

509513
public static readonly DependencyProperty DialogClosingCallbackProperty = DependencyProperty.Register(
510-
nameof(DialogClosingCallback), typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
514+
nameof(DialogClosingCallback), typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
511515

512516
/// <summary>
513517
/// Callback fired when the <see cref="DialogClosing"/> event is fired, allowing the event to be processed from a binding/view model.
@@ -678,16 +682,16 @@ private static void WatchWindowActivation(DialogHost dialogHost)
678682

679683
private void WindowOnDeactivated(object sender, EventArgs eventArgs)
680684
{
681-
_restoreFocus = _popup != null ? FocusManager.GetFocusedElement((Window)sender) : null;
685+
_restoreFocusWindowReactivation = _popup != null ? FocusManager.GetFocusedElement((Window)sender) : null;
682686
}
683687

684688
private void WindowOnActivated(object sender, EventArgs eventArgs)
685689
{
686-
if (_restoreFocus != null)
690+
if (_restoreFocusWindowReactivation != null)
687691
{
688692
Dispatcher.BeginInvoke(new Action(() =>
689693
{
690-
Keyboard.Focus(_restoreFocus);
694+
Keyboard.Focus(_restoreFocusWindowReactivation);
691695
}));
692696
}
693697
}

MaterialDesignThemes.Wpf/Snackbar.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ namespace MaterialDesignThemes.Wpf
1717
/// <summary>
1818
/// Implements a <see cref="Snackbar"/> inspired by the Material Design specs (https://material.google.com/components/snackbars-toasts.html).
1919
/// </summary>
20-
[ContentProperty("Message")]
20+
[ContentProperty(nameof(Message))]
2121
public class Snackbar : Control
2222
{
23+
private const string ActivateStoryboardName = "ActivateStoryboard";
24+
private const string DeactivateStoryboardName = "DeactivateStoryboard";
25+
2326
private Action _messageQueueRegistrationCleanUp = null;
2427

2528
static Snackbar()
@@ -28,7 +31,7 @@ static Snackbar()
2831
}
2932

3033
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
31-
"Message", typeof(SnackbarMessage), typeof(Snackbar), new PropertyMetadata(default(SnackbarMessage)));
34+
nameof(Message), typeof(SnackbarMessage), typeof(Snackbar), new PropertyMetadata(default(SnackbarMessage)));
3235

3336
public SnackbarMessage Message
3437
{
@@ -37,7 +40,7 @@ public SnackbarMessage Message
3740
}
3841

3942
public static readonly DependencyProperty MessageQueueProperty = DependencyProperty.Register(
40-
"MessageQueue", typeof(SnackbarMessageQueue), typeof(Snackbar), new PropertyMetadata(default(SnackbarMessageQueue), MessageQueuePropertyChangedCallback));
43+
nameof(MessageQueue), typeof(SnackbarMessageQueue), typeof(Snackbar), new PropertyMetadata(default(SnackbarMessageQueue), MessageQueuePropertyChangedCallback));
4144

4245
private static void MessageQueuePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
4346
{
@@ -54,7 +57,7 @@ public SnackbarMessageQueue MessageQueue
5457
}
5558

5659
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(
57-
"IsActive", typeof(bool), typeof(Snackbar), new PropertyMetadata(default(bool), IsActivePropertyChangedCallback));
60+
nameof(IsActive), typeof(bool), typeof(Snackbar), new PropertyMetadata(default(bool), IsActivePropertyChangedCallback));
5861

5962
public bool IsActive
6063
{
@@ -70,7 +73,7 @@ public event RoutedPropertyChangedEventHandler<bool> IsActiveChanged
7073

7174
public static readonly RoutedEvent IsActiveChangedEvent =
7275
EventManager.RegisterRoutedEvent(
73-
"IsActiveChanged",
76+
nameof(IsActiveChanged),
7477
RoutingStrategy.Bubble,
7578
typeof(RoutedPropertyChangedEventHandler<bool>),
7679
typeof(Snackbar));
@@ -87,7 +90,7 @@ private static void OnIsActiveChanged(
8790

8891
public static readonly RoutedEvent DeactivateStoryboardCompletedEvent =
8992
EventManager.RegisterRoutedEvent(
90-
"DeactivateStoryboardCompleted",
93+
nameof(DeactivateStoryboardCompleted),
9194
RoutingStrategy.Bubble,
9295
typeof(SnackbarMessageEventArgs),
9396
typeof(Snackbar));
@@ -110,7 +113,7 @@ private static void OnDeactivateStoryboardCompleted(
110113
public TimeSpan DeactivateStoryboardDuration { get; private set; }
111114

112115
public static readonly DependencyProperty ActionButtonStyleProperty = DependencyProperty.Register(
113-
"ActionButtonStyle", typeof(Style), typeof(Snackbar), new PropertyMetadata(default(Style)));
116+
nameof(ActionButtonStyle), typeof(Style), typeof(Snackbar), new PropertyMetadata(default(Style)));
114117

115118
public Style ActionButtonStyle
116119
{
@@ -129,8 +132,8 @@ public override void OnApplyTemplate()
129132
//(currently we have no even on the activate animation; don't
130133
// need it just now, but it would mirror the deactivate)
131134

132-
ActivateStoryboardDuration = GetStoryboardResourceDuration("ActivateStoryboard");
133-
DeactivateStoryboardDuration = GetStoryboardResourceDuration("DeactivateStoryboard");
135+
ActivateStoryboardDuration = GetStoryboardResourceDuration(ActivateStoryboardName);
136+
DeactivateStoryboardDuration = GetStoryboardResourceDuration(DeactivateStoryboardName);
134137

135138
base.OnApplyTemplate();
136139
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<Trigger Property="IsMouseOver" Value="true">
6161
<Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True" />
6262
</Trigger>
63+
<Trigger Property="IsKeyboardFocused" Value="true">
64+
<Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True" />
65+
</Trigger>
6366
<Trigger Property="IsEnabled" Value="false">
6467
<Setter Property="Opacity" Value="0.23"/>
6568
</Trigger>
@@ -205,6 +208,9 @@
205208
<Trigger Property="IsMouseOver" Value="True">
206209
<Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True" />
207210
</Trigger>
211+
<Trigger Property="IsKeyboardFocused" Value="true">
212+
<Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True" />
213+
</Trigger>
208214
</ControlTemplate.Triggers>
209215
</ControlTemplate>
210216
</Setter.Value>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Snackbar.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<TextBlock Text="{Binding}">
8585
<TextBlock.Style>
8686
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource MaterialDesignBody1TextBlock}">
87+
<Setter Property="FontSize" Value="14" />
8788
<Setter Property="TextWrapping" Value="WrapWithOverflow" />
8889
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
8990
</Style>
@@ -133,6 +134,12 @@
133134
<SineEase EasingMode="EaseOut" />
134135
</DoubleAnimation.EasingFunction>
135136
</DoubleAnimation>
137+
<DoubleAnimation Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Opacity" To="0" BeginTime="0" Duration="0" />
138+
<DoubleAnimation Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Opacity" From="0" To="1" BeginTime="0:0:0.075" Duration="0:0:0.225">
139+
<DoubleAnimation.EasingFunction>
140+
<SineEase EasingMode="EaseOut" />
141+
</DoubleAnimation.EasingFunction>
142+
</DoubleAnimation>
136143
</Storyboard>
137144
<Storyboard x:Key="DeactivateStoryboard" Duration="0:0:0.3">
138145
<DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Tag" From="1" To="0" Duration="0:0:0.3">

0 commit comments

Comments
 (0)