private BitmapSource GetSymbol(DialogSymbol symbol) { IntPtr handle; switch (symbol) { case DialogSymbol.Application: handle = SystemIcons.Application.Handle; break; case DialogSymbol.Asterisk: handle = SystemIcons.Asterisk.Handle; break; case DialogSymbol.Error: handle = SystemIcons.Error.Handle; break; case DialogSymbol.Exclamation: handle = SystemIcons.Exclamation.Handle; break; case DialogSymbol.Hand: handle = SystemIcons.Hand.Handle; break; case DialogSymbol.Information: handle = SystemIcons.Information.Handle; break; case DialogSymbol.Question: handle = SystemIcons.Question.Handle; break; case DialogSymbol.Shield: handle = SystemIcons.Shield.Handle; break; case DialogSymbol.Warning: handle = SystemIcons.Warning.Handle; break; case DialogSymbol.WinLogo: handle = SystemIcons.WinLogo.Handle; break; default: return(null); } return(Imaging.CreateBitmapSourceFromHIcon(handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); }
/// <summary> /// This constructor initialize a new instance of this class. /// </summary> /// <param name="owner"> /// The owner of the dialog box. /// </param> /// <param name="message"> /// The message to be displayed. /// </param> /// <param name="caption"> /// The dialog box caption to be used. /// </param> /// <param name="buttons"> /// The set of flags describing the used buttons. /// </param> /// <param name="symbol"> /// The dialog box symbol to be shown. /// </param> /// <param name="options"> /// The list of additional dialog box options. /// </param> public DialogBox(Window owner, String message, String caption, DialogButton buttons, DialogSymbol symbol, DialogOption[] options) { base.MinHeight = 180; base.MaxHeight = SystemParameters.WorkArea.Height; base.MinWidth = 550; // Don't change! Otherwise the link is covered by buttons if all of them are visible. base.MaxWidth = 800; base.Height = 180; base.Width = 550; this.Message = this.FixMessage(message); base.Title = this.FixCaption(owner, caption); this.Symbol = this.GetSymbol(symbol); this.Buttons = buttons; this.Result = Dialogs.DialogResult.None; this.labels = DefaultButtonLabels.CreateLabels(); this.ApplyOptions(options); this.ApplyDefaults(options); this.InitializeComponent(); base.Owner = owner; base.WindowStartupLocation = (base.Owner is null) ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner; base.ShowInTaskbar = (base.Owner is null ? true : false); base.DataContext = this; }