private static Button CreateCtrlButtonWithResult(MessageBoxModule mbox, string content, bool?dialogResult, Action action, bool isDefault = false) { var btn = CreateCtrlButton(content); btn.IsDefault = isDefault; Action actionDialogResult = new Action(() => { mbox.DialogResult = dialogResult; if (null == dialogResult) { mbox.Close(); } }); if (null == action) { action = new Action(() => { }); } Action mulitcastDelegate = (Action)MulticastDelegate.Combine(actionDialogResult, action); if (null != mulitcastDelegate) { btn.Command = new MessageBoxRelayCommand(mulitcastDelegate); } return(btn); }
/// <summary> /// 在指定窗口的前面显示消息框。该消息框显示消息、标题栏标题、按钮和图标,并接受默认消息框结果和返回结果。 /// </summary> /// <param name="owner">一个 <see cref="System.Windows.Window"/>,表示消息框的所有者窗口。</param> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <param name="caption"> 一个 <see cref="System.String"/>,用于指定要显示的标题栏标题。</param> /// <param name="button">一个 <see cref="System.Windows.MessageBoxButton"/> 值,用于指定要显示哪个按钮或哪些按钮。</param> /// <param name="icon"> /// 一个 <see cref="System.Windows.MessageBoxImage"/> 值,用于指定要显示的图标。 /// 未使用,留白. /// </param> /// <param name="defaultResult"> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定消息框的默认结果。</param> /// <returns> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult) { if (MessageBoxType == MIVMessageBoxType.System) { return(System.Windows.MessageBox.Show(owner, messageBoxText, caption, button, icon, defaultResult)); } return(MessageBoxModule.Show(owner, messageBoxText, caption, button, icon, defaultResult)); }
/// <summary> /// 在指定窗口的前面显示消息框。该消息框显示消息并返回结果。 /// </summary> /// <param name="owner">一个 <see cref="System.Windows.Window"/>,表示消息框的所有者窗口。</param> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <returns> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(Window owner, string messageBoxText) { if (MessageBoxType == MIVMessageBoxType.System) { return(System.Windows.MessageBox.Show(owner, messageBoxText)); } return(MessageBoxModule.Show(owner, messageBoxText)); }
/// <summary> /// 显示一个消息框,该消息框包含消息、标题栏标题和按钮,并且返回结果。 /// </summary> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <param name="caption"> 一个 <see cref="System.String"/>,用于指定要显示的标题栏标题。</param> /// <param name="button">一个 <see cref="System.Windows.MessageBoxButton"/> 值,用于指定要显示哪个按钮或哪些按钮。</param> /// <returns>一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) { if (MessageBoxType == MIVMessageBoxType.System) { return(System.Windows.MessageBox.Show(messageBoxText, caption, button)); } return(MessageBoxModule.Show(messageBoxText, caption, button)); }
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, IList <MessageBoxButtonInfo> ctrlButtons) { var mbox = new MessageBoxModule(); mbox.Message = messageBoxText; mbox.Title = caption; mbox.Owner = owner; IsUseCustomInfoDefine(ref mbox); if (owner != null) { mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner; } if (null != ctrlButtons && ctrlButtons.Count > 0) { foreach (var btnInfo in ctrlButtons) { switch (btnInfo.Result) { case MessageBoxResult.Cancel: case MessageBoxResult.No: { var btn = CreateCtrlButtonWithResult(mbox, btnInfo.ContentText, false, btnInfo.Action, btnInfo.IsDefault); mbox.CtrlButtonCollection.Add(btn); } break; case MessageBoxResult.None: { var btn = CreateCtrlButtonWithResult(mbox, btnInfo.ContentText, null, btnInfo.Action, btnInfo.IsDefault); mbox.CtrlButtonCollection.Add(btn); } break; case MessageBoxResult.OK: case MessageBoxResult.Yes: default: { var btn = CreateCtrlButtonWithResult(mbox, btnInfo.ContentText, true, btnInfo.Action, btnInfo.IsDefault); mbox.CtrlButtonCollection.Add(btn); } break; } } var result = mbox.ShowDialog(); return(MessageBoxResult.None); } else { return(Show(owner, messageBoxText, caption, MessageBoxButton.OK)); } }
private static void IsUseCustomInfoDefine(ref MessageBoxModule mbox) { if (B_USED_CUSTOM_BRUSHES && null != mbox) { if (MB_CUSTOMINFO.IsBackgroundChanged) { mbox.Background = MB_CUSTOMINFO.MB_Background; } if (MB_CUSTOMINFO.IsBorderBrushChanged) { mbox.BorderBrush = MB_CUSTOMINFO.MB_Borderbrush; } if (MB_CUSTOMINFO.IsBorderThicknessChanged) { mbox.BorderThickness = MB_CUSTOMINFO.MB_BorderThickness; } if (MB_CUSTOMINFO.IsForegroundChanged) { mbox.Foreground = MB_CUSTOMINFO.MB_Foreground; } if (MB_CUSTOMINFO.IsTitleForegroundChanged) { mbox.TitleForeground = MB_CUSTOMINFO.MB_Title_Foreground; } if (MB_CUSTOMINFO.IsTitleBackgroundChanged) { mbox.TitleBackground = MB_CUSTOMINFO.MB_Title_Background; } } if (B_USED_CUSTOM_SIZE && null != mbox) { if (MB_CUSTOMINFO.IsMaxHeightChanged) { mbox.MaxHeight = MB_CUSTOMINFO.MB_MaxHeight; } if (MB_CUSTOMINFO.IsMaxWidthChanged) { mbox.MaxWidth = MB_CUSTOMINFO.MB_MaxWidth; } } }
/// <summary> /// 显示一个消息框,该消息框包含消息并返回结果。 /// </summary> /// <param name="messageBoxText">一个 System.String,用于指定要显示的文本。</param> /// <returns>一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(string messageBoxText) { return(MessageBoxModule.Show(messageBoxText)); }
public static void ResetMessageBoxCustomDefine() { MessageBoxModule.ResetMessageBoxCustomDefine(); }
/// <summary> /// 设置 <see cref="Utility.Controls.LighterMessageBox"/> 的一些自定义信息. /// </summary> /// <param name="mbCustomIf"><see cref="Utility.Controls.LighterMessageBox"/> 自定义信息结构</param> public static void SetMessageBoxCustomDefine(MessageBoxCustomInfo mbCustomIf) { MessageBoxModule.SetMessageBoxCustomDefine(mbCustomIf); }
//private double maxWidth=350; //public double MaxWidth //{ // get { return maxWidth; } // set { maxWidth = value; } //} #region custom settings /// <summary> /// 设置 <see cref="Utility.Controls.LighterMessageBox"/> 的按钮样式. /// </summary> /// <param name="buttonStyle"></param> public static void SetDefaultCtorButtonStyle(Style buttonStyle) { MessageBoxModule.SetDefaultCtorButtonStyle(buttonStyle); }
/// <summary> /// /// </summary> /// <param name="owner"></param> /// <param name="messageBoxText"></param> /// <param name="caption"></param> /// <param name="button"></param> /// <param name="icon">为兼容 System.Windows.MessageBox 的留白.</param> /// <param name="defaultResult"></param> /// <returns></returns> public static MessageBoxResult Show( Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult ) { var mbox = new MessageBoxModule(); mbox.Message = messageBoxText; mbox.Title = caption; mbox.Owner = owner; IsUseCustomInfoDefine( ref mbox ); if ( owner != null ) { mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner; } switch ( button ) { case MessageBoxButton.OKCancel: mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "确定", true, null, defaultResult == MessageBoxResult.OK ) ); mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "取消", false, null, defaultResult == MessageBoxResult.Cancel ) ); break; //break; case MessageBoxButton.YesNo: mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "是", true, null, defaultResult == MessageBoxResult.Yes ) ); mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "否", false, null, defaultResult == MessageBoxResult.No ) ); break; case MessageBoxButton.YesNoCancel: mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "是", true, null, defaultResult == MessageBoxResult.Yes ) ); mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "否", false, null, defaultResult == MessageBoxResult.No ) ); mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "取消", null, null, defaultResult == MessageBoxResult.Cancel ) ); break; case MessageBoxButton.OK: default: mbox.CtrlButtonCollection.Add( CreateCtrlButtonWithResult( mbox, "确定", true, null, defaultResult == MessageBoxResult.OK ) ); break; } var result = mbox.ShowDialog(); switch ( button ) { //break; case MessageBoxButton.OKCancel: { return result == true ? MessageBoxResult.OK : result == false ? MessageBoxResult.Cancel : MessageBoxResult.None; } //break; case MessageBoxButton.YesNo: { return result == true ? MessageBoxResult.Yes : MessageBoxResult.No; } //break; case MessageBoxButton.YesNoCancel: { return result == true ? MessageBoxResult.Yes : result == false ? MessageBoxResult.No : MessageBoxResult.Cancel; } case MessageBoxButton.OK: default: { return result == true ? MessageBoxResult.OK : MessageBoxResult.None; } } }
/// <summary> /// 在指定窗口的前面显示消息框。该消息框显示消息、标题栏标题和按钮,并且支持自定义按钮和动作。 /// </summary> /// <param name="owner"> 一个 <see cref="System.Windows.Window"/>,表示消息框的所有者窗口。</param> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <param name="caption"> 一个 <see cref="System.String"/>,用于指定要显示的标题栏标题。</param> /// <param name="ctrlButtons">一组自定义的按钮和响应动作。</param> /// <returns> <paramref name="ctrlButtons"/> 中点击的 MessageBoxButtonInfo.Result 结果.</returns> public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, IList <MessageBoxButtonInfo> ctrlButtons) { return(MessageBoxModule.Show(owner, messageBoxText, caption, ctrlButtons)); }
private static void IsUseCustomInfoDefine( ref MessageBoxModule mbox ) { if ( B_USED_CUSTOM_BRUSHES && null != mbox ) { if ( MB_CUSTOMINFO.IsBackgroundChanged ) { mbox.Background = MB_CUSTOMINFO.MB_Background; } if ( MB_CUSTOMINFO.IsBorderBrushChanged ) { mbox.BorderBrush = MB_CUSTOMINFO.MB_Borderbrush; } if ( MB_CUSTOMINFO.IsBorderThicknessChanged ) { mbox.BorderThickness = MB_CUSTOMINFO.MB_BorderThickness; } if ( MB_CUSTOMINFO.IsForegroundChanged ) { mbox.Foreground = MB_CUSTOMINFO.MB_Foreground; } if ( MB_CUSTOMINFO.IsTitleForegroundChanged ) { mbox.TitleForeground = MB_CUSTOMINFO.MB_Title_Foreground; } if ( MB_CUSTOMINFO.IsTitleBackgroundChanged ) { mbox.TitleBackground = MB_CUSTOMINFO.MB_Title_Background; } } if ( B_USED_CUSTOM_SIZE && null != mbox ) { if ( MB_CUSTOMINFO.IsMaxHeightChanged ) { mbox.MaxHeight = MB_CUSTOMINFO.MB_MaxHeight; } if ( MB_CUSTOMINFO.IsMaxWidthChanged ) { mbox.MaxWidth = MB_CUSTOMINFO.MB_MaxWidth; } } }
private static Button CreateCtrlButtonWithResult( MessageBoxModule mbox, string content, bool? dialogResult, Action action, bool isDefault = false ) { var btn = CreateCtrlButton( content ); btn.IsDefault = isDefault; Action actionDialogResult = new Action( () => { mbox.DialogResult = dialogResult; if ( null == dialogResult ) mbox.Close(); } ); if ( null == action ) action = new Action( () => { } ); Action mulitcastDelegate = (Action)MulticastDelegate.Combine( actionDialogResult, action ); if ( null != mulitcastDelegate ) { btn.Command = new MessageBoxRelayCommand( mulitcastDelegate ); } return btn; }
/// <summary> /// 显示一个消息框,该消息框包含消息、标题栏标题和按钮,并且返回结果。 /// </summary> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <param name="caption"> 一个 <see cref="System.String"/>,用于指定要显示的标题栏标题。</param> /// <param name="button">一个 <see cref="System.Windows.MessageBoxButton"/> 值,用于指定要显示哪个按钮或哪些按钮。</param> /// <returns>一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) { return(MessageBoxModule.Show(messageBoxText, caption, button)); }
/// <summary> /// 在指定窗口的前面显示消息框。该消息框显示消息并返回结果。 /// </summary> /// <param name="owner">一个 <see cref="System.Windows.Window"/>,表示消息框的所有者窗口。</param> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <returns> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(Window owner, string messageBoxText) { return(MessageBoxModule.Show(owner, messageBoxText)); }
/// <summary> /// /// </summary> /// <param name="owner"></param> /// <param name="messageBoxText"></param> /// <param name="caption"></param> /// <param name="button"></param> /// <param name="icon">为兼容 System.Windows.MessageBox 的留白.</param> /// <param name="defaultResult"></param> /// <returns></returns> public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult) { var mbox = new MessageBoxModule(); mbox.Message = messageBoxText; mbox.Title = caption; mbox.Owner = owner; IsUseCustomInfoDefine(ref mbox); if (owner != null) { mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner; } switch (button) { case MessageBoxButton.OKCancel: mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "确定", true, null, defaultResult == MessageBoxResult.OK)); mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "取消", false, null, defaultResult == MessageBoxResult.Cancel)); break; //break; case MessageBoxButton.YesNo: mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "是", true, null, defaultResult == MessageBoxResult.Yes)); mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "否", false, null, defaultResult == MessageBoxResult.No)); break; case MessageBoxButton.YesNoCancel: mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "是", true, null, defaultResult == MessageBoxResult.Yes)); mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "否", false, null, defaultResult == MessageBoxResult.No)); mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "取消", null, null, defaultResult == MessageBoxResult.Cancel)); break; case MessageBoxButton.OK: default: mbox.CtrlButtonCollection.Add(CreateCtrlButtonWithResult(mbox, "确定", true, null, defaultResult == MessageBoxResult.OK)); break; } var result = mbox.ShowDialog(); switch (button) { //break; case MessageBoxButton.OKCancel: { return(result == true ? MessageBoxResult.OK : result == false ? MessageBoxResult.Cancel : MessageBoxResult.None); } //break; case MessageBoxButton.YesNo: { return(result == true ? MessageBoxResult.Yes : MessageBoxResult.No); } //break; case MessageBoxButton.YesNoCancel: { return(result == true ? MessageBoxResult.Yes : result == false ? MessageBoxResult.No : MessageBoxResult.Cancel); } case MessageBoxButton.OK: default: { return(result == true ? MessageBoxResult.OK : MessageBoxResult.None); } } }
/// <summary> /// 在指定窗口的前面显示消息框。该消息框显示消息、标题栏标题、按钮和图标,并接受默认消息框结果和返回结果。 /// </summary> /// <param name="owner">一个 <see cref="System.Windows.Window"/>,表示消息框的所有者窗口。</param> /// <param name="messageBoxText">一个 <see cref="System.String"/>,用于指定要显示的文本。</param> /// <param name="caption"> 一个 <see cref="System.String"/>,用于指定要显示的标题栏标题。</param> /// <param name="button">一个 <see cref="System.Windows.MessageBoxButton"/> 值,用于指定要显示哪个按钮或哪些按钮。</param> /// <param name="icon"> /// 一个 <see cref="System.Windows.MessageBoxImage"/> 值,用于指定要显示的图标。 /// 未使用,留白. /// </param> /// <param name="defaultResult"> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定消息框的默认结果。</param> /// <returns> 一个 <see cref="System.Windows.MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns> public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult) { return(MessageBoxModule.Show(owner, messageBoxText, caption, button, icon, defaultResult)); }
public static MessageBoxResult Show( Window owner, string messageBoxText, string caption, IList<MessageBoxButtonInfo> ctrlButtons ) { var mbox = new MessageBoxModule(); mbox.Message = messageBoxText; mbox.Title = caption; mbox.Owner = owner; IsUseCustomInfoDefine( ref mbox ); if ( owner != null ) { mbox.WindowStartupLocation = WindowStartupLocation.CenterOwner; } if ( null != ctrlButtons && ctrlButtons.Count > 0 ) { foreach ( var btnInfo in ctrlButtons ) { switch ( btnInfo.Result ) { case MessageBoxResult.Cancel: case MessageBoxResult.No: { var btn = CreateCtrlButtonWithResult( mbox, btnInfo.ContentText, false, btnInfo.Action, btnInfo.IsDefault ); mbox.CtrlButtonCollection.Add( btn ); } break; case MessageBoxResult.None: { var btn = CreateCtrlButtonWithResult( mbox, btnInfo.ContentText, null, btnInfo.Action, btnInfo.IsDefault ); mbox.CtrlButtonCollection.Add( btn ); } break; case MessageBoxResult.OK: case MessageBoxResult.Yes: default: { var btn = CreateCtrlButtonWithResult( mbox, btnInfo.ContentText, true, btnInfo.Action, btnInfo.IsDefault ); mbox.CtrlButtonCollection.Add( btn ); } break; } } var result = mbox.ShowDialog(); return MessageBoxResult.None; } else { return Show( owner, messageBoxText, caption, MessageBoxButton.OK ); } }