enhance: closed #1710
This commit is contained in:
1 parent
49b2befc96
commit
0f65abbfcc
2 files changed
+256
-193
No files matched your search
@@ -16,78 +16,44 @@ using HandyControl.Tools.Interop;
|
||||
namespace HandyControl.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// 消息框
|
||||
/// Displays a message box with text, buttons, and symbols to inform and instruct the user.
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "RedundantDelegateCreation")]
|
||||
[TemplatePart(Name = ElementPanel, Type = typeof(Panel))]
|
||||
[TemplatePart(Name = ElementButtonClose, Type = typeof(Button))]
|
||||
|
||||
public sealed class MessageBox : Window
|
||||
{
|
||||
private const string ElementPanel = "PART_Panel";
|
||||
|
||||
private const string ElementButtonClose = "PART_ButtonClose";
|
||||
|
||||
private Button _buttonClose;
|
||||
|
||||
private Panel _panel;
|
||||
|
||||
private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel;
|
||||
|
||||
private Button _buttonOk;
|
||||
|
||||
private Button _buttonCancel;
|
||||
|
||||
private Button _buttonYes;
|
||||
|
||||
private Button _buttonNo;
|
||||
|
||||
private bool _showOk;
|
||||
|
||||
private bool _showCancel;
|
||||
|
||||
private bool _showYes;
|
||||
|
||||
private bool _showNo;
|
||||
|
||||
private IntPtr _lastActiveWindowIntPtr;
|
||||
|
||||
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
|
||||
nameof(Message), typeof(string), typeof(MessageBox), new PropertyMetadata(default(string)));
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => (string) GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(
|
||||
nameof(Image), typeof(Geometry), typeof(MessageBox), new PropertyMetadata(default(Geometry)));
|
||||
|
||||
public Geometry Image
|
||||
{
|
||||
get => (Geometry) GetValue(ImageProperty);
|
||||
set => SetValue(ImageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ImageBrushProperty = DependencyProperty.Register(
|
||||
nameof(ImageBrush), typeof(Brush), typeof(MessageBox), new PropertyMetadata(default(Brush)));
|
||||
|
||||
public Brush ImageBrush
|
||||
{
|
||||
get => (Brush) GetValue(ImageBrushProperty);
|
||||
set => SetValue(ImageBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowImageProperty = DependencyProperty.Register(
|
||||
nameof(ShowImage), typeof(bool), typeof(MessageBox), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool ShowImage
|
||||
{
|
||||
get => (bool) GetValue(ShowImageProperty);
|
||||
set => SetValue(ShowImageProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
private Button _buttonClose;
|
||||
private Panel _panel;
|
||||
private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel;
|
||||
private Button _buttonOk;
|
||||
private Button _buttonCancel;
|
||||
private Button _buttonYes;
|
||||
private Button _buttonNo;
|
||||
private bool _showOk;
|
||||
private bool _showCancel;
|
||||
private bool _showYes;
|
||||
private bool _showNo;
|
||||
private IntPtr _lastActiveWindowIntPtr;
|
||||
|
||||
/// <summary>
|
||||
/// This constructor is private so people aren't tempted to try and create instances of these -- they should just use the static methods.
|
||||
/// </summary>
|
||||
private MessageBox()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Confirm, (s, e) =>
|
||||
@@ -112,6 +78,30 @@ public sealed class MessageBox : Window
|
||||
}, (s, e) => e.CanExecute = _showNo));
|
||||
}
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => (string) GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
public Geometry Image
|
||||
{
|
||||
get => (Geometry) GetValue(ImageProperty);
|
||||
set => SetValue(ImageProperty, value);
|
||||
}
|
||||
|
||||
public Brush ImageBrush
|
||||
{
|
||||
get => (Brush) GetValue(ImageBrushProperty);
|
||||
set => SetValue(ImageBrushProperty, value);
|
||||
}
|
||||
|
||||
public bool ShowImage
|
||||
{
|
||||
get => (bool) GetValue(ShowImageProperty);
|
||||
set => SetValue(ShowImageProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
{
|
||||
if (_showYes && !_showCancel)
|
||||
@@ -119,7 +109,8 @@ public sealed class MessageBox : Window
|
||||
var hMenu = InteropMethods.GetSystemMenu(this.GetHandle(), false);
|
||||
if (hMenu != IntPtr.Zero)
|
||||
{
|
||||
InteropMethods.EnableMenuItem(hMenu, InteropValues.SC_CLOSE, InteropValues.MF_BYCOMMAND | InteropValues.MF_GRAYED);
|
||||
InteropMethods.EnableMenuItem(hMenu, InteropValues.SC_CLOSE,
|
||||
InteropValues.MF_BYCOMMAND | InteropValues.MF_GRAYED);
|
||||
}
|
||||
|
||||
if (_buttonClose != null)
|
||||
@@ -180,72 +171,88 @@ public sealed class MessageBox : Window
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.System && e.SystemKey == Key.F4)
|
||||
if (e is { Key: Key.System, SystemKey: Key.F4 })
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C)
|
||||
if (e.KeyboardDevice.Modifiers != ModifierKeys.Control || e.Key != Key.C)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
var line = new string('-', 27);
|
||||
builder.Append(line);
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(Title);
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(line);
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(Message);
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(line);
|
||||
builder.Append(Environment.NewLine);
|
||||
if (_showOk)
|
||||
{
|
||||
builder.Append(Lang.Confirm);
|
||||
builder.Append(" ");
|
||||
}
|
||||
if (_showYes)
|
||||
{
|
||||
builder.Append(Lang.Yes);
|
||||
builder.Append(" ");
|
||||
}
|
||||
if (_showNo)
|
||||
{
|
||||
builder.Append(Lang.No);
|
||||
builder.Append(" ");
|
||||
}
|
||||
if (_showCancel)
|
||||
{
|
||||
builder.Append(Lang.Cancel);
|
||||
builder.Append(" ");
|
||||
}
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(line);
|
||||
builder.Append(Environment.NewLine);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Clipboard.SetDataObject(builder.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
const int dashCount = 27;
|
||||
var line = new string('-', dashCount);
|
||||
|
||||
var builder = new StringBuilder()
|
||||
.Append(line)
|
||||
.Append(Environment.NewLine)
|
||||
.Append(Title)
|
||||
.Append(Environment.NewLine)
|
||||
.Append(line)
|
||||
.Append(Environment.NewLine)
|
||||
.Append(Message)
|
||||
.Append(Environment.NewLine)
|
||||
.Append(line)
|
||||
.Append(Environment.NewLine);
|
||||
|
||||
if (_showOk)
|
||||
{
|
||||
builder.Append(Lang.Confirm);
|
||||
builder.Append(" ");
|
||||
}
|
||||
|
||||
if (_showYes)
|
||||
{
|
||||
builder.Append(Lang.Yes);
|
||||
builder.Append(" ");
|
||||
}
|
||||
|
||||
if (_showNo)
|
||||
{
|
||||
builder.Append(Lang.No);
|
||||
builder.Append(" ");
|
||||
}
|
||||
|
||||
if (_showCancel)
|
||||
{
|
||||
builder.Append(Lang.Cancel);
|
||||
builder.Append(" ");
|
||||
}
|
||||
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(line);
|
||||
builder.Append(Environment.NewLine);
|
||||
|
||||
try
|
||||
{
|
||||
Clipboard.SetDataObject(builder.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 成功
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Success(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Success(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Success(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OK,
|
||||
icon: MessageBoxImage.None,
|
||||
defaultResult: MessageBoxResult.OK
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(ResourceToken.SuccessGeometry);
|
||||
@@ -257,17 +264,24 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Info(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Info(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Info(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OK,
|
||||
icon: MessageBoxImage.Information,
|
||||
defaultResult: MessageBoxResult.OK
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Information);
|
||||
SystemSounds.Asterisk.Play();
|
||||
@@ -277,17 +291,24 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 警告
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Warning(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Warning(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Warning(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OK,
|
||||
icon: MessageBoxImage.Warning,
|
||||
defaultResult: MessageBoxResult.OK
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Warning);
|
||||
SystemSounds.Asterisk.Play();
|
||||
@@ -297,17 +318,24 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 错误
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Error(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Error(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Error(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OK,
|
||||
icon: MessageBoxImage.Error,
|
||||
defaultResult: MessageBoxResult.OK
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Error);
|
||||
SystemSounds.Asterisk.Play();
|
||||
@@ -317,17 +345,24 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 严重
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Fatal(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Fatal(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Fatal(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OK,
|
||||
icon: MessageBoxImage.None,
|
||||
defaultResult: MessageBoxResult.OK
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(ResourceToken.FatalGeometry);
|
||||
@@ -339,17 +374,24 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 询问
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Ask(string messageBoxText, string caption = null)
|
||||
{
|
||||
return Ask(owner: null, messageBoxText, caption);
|
||||
}
|
||||
|
||||
public static MessageBoxResult Ask(System.Windows.Window owner, string messageBoxText, string caption = null)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: owner,
|
||||
messageBoxText: messageBoxText,
|
||||
caption: caption,
|
||||
button: MessageBoxButton.OKCancel,
|
||||
icon: MessageBoxImage.Question,
|
||||
defaultResult: MessageBoxResult.Cancel
|
||||
);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OKCancel, MessageBoxResult.Cancel);
|
||||
SetImage(messageBox, MessageBoxImage.Question);
|
||||
SystemSounds.Asterisk.Play();
|
||||
@@ -359,17 +401,19 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义信息展示
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(MessageBoxInfo info)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, info.Message, info.Caption, info.Button, MessageBoxImage.None, info.DefaultResult);
|
||||
messageBox = CreateMessageBox(
|
||||
owner: info.Owner,
|
||||
messageBoxText: info.Message,
|
||||
caption: info.Caption,
|
||||
button: info.Button,
|
||||
icon: MessageBoxImage.None,
|
||||
defaultResult: info.DefaultResult
|
||||
);
|
||||
SetButtonStatus(messageBox, info.Button, info.DefaultResult);
|
||||
|
||||
if (!string.IsNullOrEmpty(info.IconKey))
|
||||
@@ -383,6 +427,7 @@ public sealed class MessageBox : Window
|
||||
{
|
||||
messageBox.Style = ResourceHelper.GetResource<Style>(info.StyleKey) ?? info.Style;
|
||||
}
|
||||
|
||||
SystemSounds.Asterisk.Play();
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
@@ -390,31 +435,25 @@ public sealed class MessageBox : Window
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信息展示
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="defaultResult"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(string messageBoxText, string caption = null,
|
||||
MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None,
|
||||
MessageBoxResult defaultResult = MessageBoxResult.None) =>
|
||||
Show(null, messageBoxText, caption, button, icon, defaultResult);
|
||||
public static MessageBoxResult Show(
|
||||
string messageBoxText,
|
||||
string caption = null,
|
||||
MessageBoxButton button = MessageBoxButton.OK,
|
||||
MessageBoxImage icon = MessageBoxImage.None,
|
||||
MessageBoxResult defaultResult = MessageBoxResult.None
|
||||
)
|
||||
{
|
||||
return Show(owner: null, messageBoxText, caption, button, icon, defaultResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信息展示
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="defaultResult"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption = null, MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None)
|
||||
public static MessageBoxResult Show(
|
||||
System.Windows.Window owner,
|
||||
string messageBoxText,
|
||||
string caption = null,
|
||||
MessageBoxButton button = MessageBoxButton.OK,
|
||||
MessageBoxImage icon = MessageBoxImage.None,
|
||||
MessageBoxResult defaultResult = MessageBoxResult.None
|
||||
)
|
||||
{
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
@@ -435,19 +474,23 @@ public sealed class MessageBox : Window
|
||||
string caption,
|
||||
MessageBoxButton button,
|
||||
MessageBoxImage icon,
|
||||
MessageBoxResult defaultResult)
|
||||
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));
|
||||
throw new InvalidEnumArgumentException(nameof(defaultResult), (int) defaultResult,
|
||||
typeof(MessageBoxResult));
|
||||
}
|
||||
|
||||
var ownerWindow = owner ?? WindowHelper.GetActiveWindow();
|
||||
@@ -457,7 +500,8 @@ public sealed class MessageBox : Window
|
||||
{
|
||||
Message = messageBoxText,
|
||||
Owner = ownerWindow,
|
||||
WindowStartupLocation = ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner,
|
||||
WindowStartupLocation =
|
||||
ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner,
|
||||
ShowTitle = true,
|
||||
Title = caption ?? string.Empty,
|
||||
Topmost = ownerIsNull,
|
||||
@@ -465,7 +509,11 @@ public sealed class MessageBox : Window
|
||||
};
|
||||
}
|
||||
|
||||
private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton messageBoxButton, MessageBoxResult defaultResult)
|
||||
private static void SetButtonStatus(
|
||||
MessageBox messageBox,
|
||||
MessageBoxButton messageBoxButton,
|
||||
MessageBoxResult defaultResult
|
||||
)
|
||||
{
|
||||
switch (messageBoxButton)
|
||||
{
|
||||
@@ -502,12 +550,14 @@ public sealed class MessageBox : Window
|
||||
if (defaultResult == MessageBoxResult.Cancel)
|
||||
{
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonOk.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonOk.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonOk.IsDefault = true;
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
@@ -532,12 +582,14 @@ public sealed class MessageBox : Window
|
||||
if (defaultResult == MessageBoxResult.No)
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.IsDefault = true;
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
@@ -570,7 +622,8 @@ public sealed class MessageBox : Window
|
||||
if (defaultResult == MessageBoxResult.No)
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonNo.IsDefault = true;
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
}
|
||||
@@ -578,12 +631,14 @@ public sealed class MessageBox : Window
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonCancel.IsDefault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBox._buttonYes.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.Style =
|
||||
ResourceHelper.GetResourceInternal<Style>("MessageBoxPrimaryButtonStyle");
|
||||
messageBox._buttonYes.IsDefault = true;
|
||||
messageBox._buttonNo.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
messageBox._buttonCancel.Style = ResourceHelper.GetResourceInternal<Style>("MessageBoxButtonStyle");
|
||||
@@ -618,7 +673,11 @@ public sealed class MessageBox : Window
|
||||
break;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(iconKey)) return;
|
||||
if (string.IsNullOrEmpty(iconKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
messageBox.ShowImage = true;
|
||||
messageBox.Image = ResourceHelper.GetResourceInternal<Geometry>(iconKey);
|
||||
messageBox.ImageBrush = ResourceHelper.GetResourceInternal<Brush>(iconBrushKey);
|
||||
@@ -626,32 +685,34 @@ public sealed class MessageBox : Window
|
||||
|
||||
private static bool IsValidMessageBoxButton(MessageBoxButton value)
|
||||
{
|
||||
return value == MessageBoxButton.OK
|
||||
|| value == MessageBoxButton.OKCancel
|
||||
|| value == MessageBoxButton.YesNo
|
||||
|| value == MessageBoxButton.YesNoCancel;
|
||||
return value
|
||||
is MessageBoxButton.OK
|
||||
or MessageBoxButton.OKCancel
|
||||
or MessageBoxButton.YesNo
|
||||
or MessageBoxButton.YesNoCancel;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse")]
|
||||
private static bool IsValidMessageBoxImage(MessageBoxImage value)
|
||||
{
|
||||
return value == MessageBoxImage.Asterisk
|
||||
|| value == MessageBoxImage.Error
|
||||
|| value == MessageBoxImage.Exclamation
|
||||
|| value == MessageBoxImage.Hand
|
||||
|| value == MessageBoxImage.Information
|
||||
|| value == MessageBoxImage.None
|
||||
|| value == MessageBoxImage.Question
|
||||
|| value == MessageBoxImage.Stop
|
||||
|| value == MessageBoxImage.Warning;
|
||||
return value
|
||||
is MessageBoxImage.Asterisk
|
||||
or MessageBoxImage.Error
|
||||
or MessageBoxImage.Exclamation
|
||||
or MessageBoxImage.Hand
|
||||
or MessageBoxImage.Information
|
||||
or MessageBoxImage.None
|
||||
or MessageBoxImage.Question
|
||||
or MessageBoxImage.Stop
|
||||
or MessageBoxImage.Warning;
|
||||
}
|
||||
|
||||
private static bool IsValidMessageBoxResult(MessageBoxResult value)
|
||||
{
|
||||
return value == MessageBoxResult.Cancel
|
||||
|| value == MessageBoxResult.No
|
||||
|| value == MessageBoxResult.None
|
||||
|| value == MessageBoxResult.OK
|
||||
|| value == MessageBoxResult.Yes;
|
||||
return value
|
||||
is MessageBoxResult.Cancel
|
||||
or MessageBoxResult.No
|
||||
or MessageBoxResult.None
|
||||
or MessageBoxResult.OK
|
||||
or MessageBoxResult.Yes;
|
||||
}
|
||||
}
|
||||
@@ -24,4 +24,6 @@ public class MessageBoxInfo
|
||||
public Style Style { get; set; }
|
||||
|
||||
public string StyleKey { get; set; }
|
||||
|
||||
public Window Owner { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user