private static MessageBox CreateMessageBox( System.Windows.Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult) { if (!IsValidMessageBoxButton(button)) { throw new InvalidEnumArgumentException(nameof(button), (int)button, typeof(MessageBoxButton)); } if (!IsValidMessageBoxImage(icon)) { throw new InvalidEnumArgumentException(nameof(icon), (int)icon, typeof(MessageBoxImage)); } if (!IsValidMessageBoxResult(defaultResult)) { throw new InvalidEnumArgumentException(nameof(defaultResult), (int)defaultResult, typeof(MessageBoxResult)); } var ownerWindow = owner ?? VisualHelper.GetActiveWindow(); var ownerIsNull = ownerWindow is null; return(new MessageBox { _message = messageBoxText, Owner = ownerWindow, WindowStartupLocation = ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner, ShowTitle = true, Title = caption ?? string.Empty, Topmost = ownerIsNull, _messageBoxResult = defaultResult }); }
public static Dialog Show(object content) { var dialog = new Dialog { Content = content }; var window = VisualHelper.GetActiveWindow(); if (window != null) { var decorator = VisualHelper.GetChild <AdornerDecorator>(window); if (decorator != null) { if (decorator.Child != null) { decorator.Child.IsEnabled = false; } var layer = decorator.AdornerLayer; if (layer != null) { var container = new AdornerContainer(layer) { Child = dialog }; dialog._container = container; layer.Add(container); } } } return(dialog); }
public void Close() { var window = VisualHelper.GetActiveWindow(); if (window != null) { var decorator = VisualHelper.GetChild <AdornerDecorator>(window); if (decorator != null) { if (decorator.Child != null) { decorator.Child.IsEnabled = true; } var layer = decorator.AdornerLayer; layer?.Remove(_container); } } }