Merge branch 'master' into pr/1705
This commit is contained in:
commit
944830c442
8 files changed
+277
-207
No files matched your search
@@ -1,6 +1,3 @@
|
||||
## 找工作
|
||||
由于个人原因,预计于年后离职,大家如果在上海,且有 python、wpf 空缺的岗位,可联系我,我的邮箱:836904362@qq.com。
|
||||
|
||||
## 友情链接
|
||||
|
||||
[SimpleFactoryGenerator](https://github.com/DingpingZhang/SimpleFactoryGenerator) - A simple factory source generator that enables the pattern to not violate the open-close principle.
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
## 找工作
|
||||
由于个人原因,预计于年后离职,大家如果在上海,且有 python、wpf 空缺的岗位,可联系我,我的邮箱:836904362@qq.com。
|
||||
|
||||
## Blogroll
|
||||
|
||||
[SimpleFactoryGenerator](https://github.com/DingpingZhang/SimpleFactoryGenerator) - A simple factory source generator that enables the pattern to not violate the open-close principle.
|
||||
|
||||
@@ -13625,6 +13625,7 @@
|
||||
<Style x:Key="TabControlCapsule" TargetType="TabControl">
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||
<Setter Property="hc:TitleElement.BorderBrush" Value="{DynamicResource PrimaryBrush}" />
|
||||
<Setter Property="hc:TitleElement.Background" Value="{DynamicResource RegionBrush}" />
|
||||
<Setter Property="hc:TitleElement.Foreground" Value="{DynamicResource PrimaryBrush}" />
|
||||
@@ -13646,7 +13647,7 @@
|
||||
<RowDefinition x:Name="RowDefinition1" Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<UniformGrid Rows="1" KeyboardNavigation.TabNavigation="Once" KeyboardNavigation.DirectionalNavigation="Cycle" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="0" Grid.Row="0" />
|
||||
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{DynamicResource BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
|
||||
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
|
||||
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<hc:SimplePanel Margin="32" VerticalAlignment="Center">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<GroupBox Header="ContextMenu" Padding="10">
|
||||
<GroupBox Header="ContextMenu" Padding="10" Background="{DynamicResource RegionBrush}">
|
||||
<StackPanel>
|
||||
<GroupBox hc:TitleElement.TitlePlacement="Left" Style="{StaticResource GroupBoxOriginal}" Header="{ex:Lang Key={x:Static langs:LangKeys.Visibility}}">
|
||||
<ToggleButton IsChecked="{Binding ContextMenuIsShow}" Style="{StaticResource ToggleButtonSwitch}"/>
|
||||
@@ -22,7 +22,7 @@
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
<GroupBox Header="ContextContent" Margin="16,0,0,0" Padding="10">
|
||||
<GroupBox Header="ContextContent" Margin="16,0,0,0" Padding="10" Background="{DynamicResource RegionBrush}">
|
||||
<StackPanel>
|
||||
<GroupBox hc:TitleElement.TitlePlacement="Left" Style="{StaticResource GroupBoxOriginal}" Header="{ex:Lang Key={x:Static langs:LangKeys.Visibility}}">
|
||||
<ToggleButton IsChecked="{Binding ContextContentIsShow}" Style="{StaticResource ToggleButtonSwitch}"/>
|
||||
|
||||
@@ -62,7 +62,7 @@ public class NotifyIcon : FrameworkElement, IDisposable
|
||||
|
||||
static NotifyIcon()
|
||||
{
|
||||
VisibilityProperty.OverrideMetadata(typeof(NotifyIcon), new PropertyMetadata(Visibility.Visible, OnVisibilityChanged));
|
||||
VisibilityProperty.OverrideMetadata(typeof(NotifyIcon), new PropertyMetadata(ValueBoxes.VisibleBox, OnVisibilityChanged));
|
||||
DataContextProperty.OverrideMetadata(typeof(NotifyIcon), new FrameworkPropertyMetadata(DataContextPropertyChanged));
|
||||
ContextMenuProperty.OverrideMetadata(typeof(NotifyIcon), new FrameworkPropertyMetadata(ContextMenuPropertyChanged));
|
||||
}
|
||||
@@ -247,7 +247,19 @@ public class NotifyIcon : FrameworkElement, IDisposable
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
|
||||
nameof(Text), typeof(string), typeof(NotifyIcon), new PropertyMetadata(default(string)));
|
||||
nameof(Text), typeof(string), typeof(NotifyIcon), new PropertyMetadata(default(string), OnTextChanged));
|
||||
|
||||
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (NotifyIcon) d;
|
||||
|
||||
if (ctl._windowClassName == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ctl.UpdateIcon(ctl._added, ctl._isTransparent);
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
@@ -309,7 +321,6 @@ public class NotifyIcon : FrameworkElement, IDisposable
|
||||
private static void OnIsBlinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (NotifyIcon) d;
|
||||
if (ctl.Visibility != Visibility.Visible) return;
|
||||
if ((bool) e.NewValue)
|
||||
{
|
||||
if (ctl._dispatcherTimerBlink == null)
|
||||
@@ -326,7 +337,7 @@ public class NotifyIcon : FrameworkElement, IDisposable
|
||||
{
|
||||
ctl._dispatcherTimerBlink?.Stop();
|
||||
ctl._dispatcherTimerBlink = null;
|
||||
ctl.UpdateIcon(true);
|
||||
ctl.UpdateIcon(ctl._added, ctl._isTransparent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -13777,6 +13777,7 @@
|
||||
<Style x:Key="TabControlCapsule" TargetType="TabControl">
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||
<Setter Property="hc:TitleElement.BorderBrush" Value="{DynamicResource PrimaryBrush}" />
|
||||
<Setter Property="hc:TitleElement.Background" Value="{DynamicResource RegionBrush}" />
|
||||
<Setter Property="hc:TitleElement.Foreground" Value="{DynamicResource PrimaryBrush}" />
|
||||
@@ -13798,7 +13799,7 @@
|
||||
<RowDefinition x:Name="RowDefinition1" Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<UniformGrid Rows="1" KeyboardNavigation.TabNavigation="Once" KeyboardNavigation.DirectionalNavigation="Cycle" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="0" Grid.Row="0" />
|
||||
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{DynamicResource BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
|
||||
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
|
||||
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
Reference in new issue
Block a user