private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var dialogHost = (DialogHost)dependencyObject; if (dialogHost._popupContentControl != null) { ValidationAssist.SetSuppress(dialogHost._popupContentControl, !dialogHost.IsOpen); } VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost)); if (dialogHost.IsOpen) { WatchWindowActivation(dialogHost); dialogHost._currentSnackbarMessageQueueUnPauseAction = dialogHost.SnackbarMessageQueue?.Pause(); } else { dialogHost._asyncShowWaitHandle.Set(); dialogHost._attachedDialogClosingEventHandler = null; if (dialogHost._currentSnackbarMessageQueueUnPauseAction != null) { dialogHost._currentSnackbarMessageQueueUnPauseAction(); dialogHost._currentSnackbarMessageQueueUnPauseAction = null; } dialogHost._session.IsEnded = true; dialogHost._session = null; dialogHost._closeCleanUp(); dialogHost.Dispatcher.InvokeAsync(() => dialogHost._restoreFocusDialogClose.Focus(), DispatcherPriority.Input); return; } dialogHost._asyncShowWaitHandle.Reset(); dialogHost._session = new DialogSession(dialogHost); var window = Window.GetWindow(dialogHost); dialogHost._restoreFocusDialogClose = window != null?FocusManager.GetFocusedElement(window) : null; //multiple ways of calling back that the dialog has opened: // * routed event // * the attached property (which should be applied to the button which opened the dialog // * straight forward dependency property // * handler provided to the async show method var dialogOpenedEventArgs = new DialogOpenedEventArgs(dialogHost._session, DialogOpenedEvent); dialogHost.OnDialogOpened(dialogOpenedEventArgs); dialogHost._attachedDialogOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.DialogOpenedCallback?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost._asyncShowOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { var child = dialogHost.FocusPopup(); //https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues/187 //totally not happy about this, but on immediate validation we can get some weird looking stuff...give WPF a kick to refresh... Task.Delay(300).ContinueWith(t => child.Dispatcher.BeginInvoke(new Action(() => child.InvalidateVisual()))); })); }
private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var dialogHost = (DialogHost)dependencyObject; ValidationAssist.SetSuppress(dialogHost._popupContentControl, !dialogHost.IsOpen); VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost)); if (!dialogHost.IsOpen) { dialogHost._asyncShowWaitHandle.Set(); dialogHost._attachedDialogClosingEventHandler = null; dialogHost._session.IsEnded = true; dialogHost._session = null; return; } dialogHost._asyncShowWaitHandle.Reset(); dialogHost._session = new DialogSession(dialogHost); //multiple ways of calling back that the dialog has opened: // * routed event // * the attached property (which should be applied to the button which opened the dialog // * straight forward dependency property // * handler provided to the async show method var dialogOpenedEventArgs = new DialogOpenedEventArgs(dialogHost._session, DialogOpenedEvent); dialogHost.OnDialogOpened(dialogOpenedEventArgs); dialogHost._attachedDialogOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.DialogOpenedCallback?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost._asyncShowOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { var child = dialogHost._popup?.Child; if (child == null) { return; } child.Focus(); child.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); //https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues/187 //totally not happy about this, but on immediate validation we can get some wierd looking stuff...give WPF a kick to refresh... Task.Delay(300).ContinueWith(t => child.Dispatcher.BeginInvoke(new Action(() => child.InvalidateVisual()))); })); }
private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var dialogHost = (DialogHost)dependencyObject; VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost)); if (!dialogHost.IsOpen) { dialogHost._asyncShowWaitHandle.Set(); dialogHost._attachedDialogClosingEventHandler = null; dialogHost._session.IsEnded = true; dialogHost._session = null; return; } dialogHost._asyncShowWaitHandle.Reset(); dialogHost._session = new DialogSession(dialogHost); //multiple ways of calling back that the dialog has opened: // * routed event // * the attached property (which should be applied to the button which opened the dialog // * straight forward dependency property // * handler provided to the async show method var dialogOpenedEventArgs = new DialogOpenedEventArgs(dialogHost._session, DialogOpenedEvent); dialogHost.OnDialogOpened(dialogOpenedEventArgs); dialogHost._attachedDialogOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.DialogOpenedCallback?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost._asyncShowOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { dialogHost._popup?.Child?.Focus(); dialogHost._popup?.Child?.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); })); }
private static void DisplayModePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { ((Clock)dependencyObject).GotoVisualState(!TransitionAssist.GetDisableTransitions(dependencyObject)); }
private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var dialogHost = (DialogHost)dependencyObject; if (dialogHost._popupContentControl != null) { ValidationAssist.SetSuppress(dialogHost._popupContentControl, !dialogHost.IsOpen); } VisualStateManager.GoToState(dialogHost, dialogHost.SelectState(), !TransitionAssist.GetDisableTransitions(dialogHost)); if (dialogHost.IsOpen) { WatchWindowActivation(dialogHost); dialogHost._currentSnackbarMessageQueueUnPauseAction = dialogHost.SnackbarMessageQueue?.Pause(); } else { dialogHost._attachedDialogClosingEventHandler = null; if (dialogHost._currentSnackbarMessageQueueUnPauseAction != null) { dialogHost._currentSnackbarMessageQueueUnPauseAction(); dialogHost._currentSnackbarMessageQueueUnPauseAction = null; } dialogHost.CurrentSession.IsEnded = true; dialogHost.CurrentSession = null; dialogHost._closeCleanUp(); //NB: _dialogTaskCompletionSource is only set in the case where the dialog is shown with Show //To get into this case you need to display the dialog with Show and then hide it by setting IsOpen to false //Setting this here ensures the other dialogHost._dialogTaskCompletionSource?.TrySetResult(null); // Don't attempt to Invoke if _restoreFocusDialogClose hasn't been assigned yet. Can occur // if the MainWindow has started up minimized. Even when Show() has been called, this doesn't // seem to have been set. dialogHost.Dispatcher.InvokeAsync(() => dialogHost._restoreFocusDialogClose?.Focus(), DispatcherPriority.Input); return; } dialogHost.CurrentSession = new DialogSession(dialogHost); var window = Window.GetWindow(dialogHost); dialogHost._restoreFocusDialogClose = window != null?FocusManager.GetFocusedElement(window) : null; //multiple ways of calling back that the dialog has opened: // * routed event // * the attached property (which should be applied to the button which opened the dialog // * straight forward dependency property // * handler provided to the async show method var dialogOpenedEventArgs = new DialogOpenedEventArgs(dialogHost.CurrentSession, DialogOpenedEvent); dialogHost.OnDialogOpened(dialogOpenedEventArgs); dialogHost._attachedDialogOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.DialogOpenedCallback?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost._asyncShowOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs); dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { CommandManager.InvalidateRequerySuggested(); UIElement child = dialogHost.FocusPopup(); if (child != null) { //https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues/187 //totally not happy about this, but on immediate validation we can get some weird looking stuff...give WPF a kick to refresh... Task.Delay(300).ContinueWith(t => child.Dispatcher.BeginInvoke(new Action(() => child.InvalidateVisual()))); } })); }
private void UpdateVisualStates(bool?useTransitions = null) { var anyOpen = IsTopDrawerOpen || IsLeftDrawerOpen || IsBottomDrawerOpen || IsRightDrawerOpen; VisualStateManager.GoToState(this, !anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this)); VisualStateManager.GoToState(this, IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this)); VisualStateManager.GoToState(this, IsTopDrawerOpen ? TemplateTopOpenStateName : TemplateTopClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this)); VisualStateManager.GoToState(this, IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this)); VisualStateManager.GoToState(this, IsBottomDrawerOpen ? TemplateBottomOpenStateName : TemplateBottomClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this)); }
private void UpdateVisualStates(bool useTransitions) { var anyOpen = IsLeftDrawerOpen; VisualStateManager.GoToState(this, !anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName, !TransitionAssist.GetDisableTransitions(this)); VisualStateManager.GoToState(this, IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName, !TransitionAssist.GetDisableTransitions(this)); }
private static void IsActivePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { ((Underline)dependencyObject).GotoVisualState(!TransitionAssist.GetDisableTransitions(dependencyObject)); }