fixed #484
This commit is contained in:
1 parent
46d8e8bc65
commit
4ef70ba91d
5 files changed
+237
-38
No files matched your search
@@ -1,16 +1,26 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:hc="clr-namespace:HandyControl.Controls"
|
xmlns:hc="clr-namespace:HandyControl.Controls"
|
||||||
xmlns:langs="clr-namespace:HandyControl.Properties.Langs"
|
|
||||||
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
|
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
|
||||||
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
|
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
|
||||||
xmlns:ex="clr-namespace:HandyControl.Tools.Extension"
|
|
||||||
xmlns:themes="clr-namespace:HandyControl.Themes">
|
xmlns:themes="clr-namespace:HandyControl.Themes">
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Window.xaml"/>
|
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Window.xaml"/>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
<Style x:Key="MessageBoxButtonStyle" BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
|
||||||
|
<Setter Property="MinWidth" Value="88"/>
|
||||||
|
<Setter Property="Visibility" Value="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}"/>
|
||||||
|
<Setter Property="Margin" Value="5,0"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="MessageBoxPrimaryButtonStyle" BasedOn="{StaticResource ButtonPrimary}" TargetType="Button">
|
||||||
|
<Setter Property="MinWidth" Value="88"/>
|
||||||
|
<Setter Property="Visibility" Value="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}"/>
|
||||||
|
<Setter Property="Margin" Value="5,0"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
<Style TargetType="hc:MessageBox" BasedOn="{StaticResource WindowWin10}">
|
<Style TargetType="hc:MessageBox" BasedOn="{StaticResource WindowWin10}">
|
||||||
<Setter Property="MinHeight" Value="172"/>
|
<Setter Property="MinHeight" Value="172"/>
|
||||||
<Setter Property="ShowInTaskbar" Value="False"/>
|
<Setter Property="ShowInTaskbar" Value="False"/>
|
||||||
@@ -34,7 +44,7 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<StackPanel shell:WindowChrome.IsHitTestVisibleInChrome="True" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
<StackPanel shell:WindowChrome.IsHitTestVisibleInChrome="True" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||||
<Button Background="{TemplateBinding CloseButtonBackground}" Foreground="{TemplateBinding CloseButtonForeground}" Command="shell:SystemCommands.CloseWindowCommand" IsTabStop="False" Name="ButtonClose" Height="29" Style="{StaticResource ButtonIcon}" Width="46" hc:IconElement.Geometry="{StaticResource CloseGeometry}" BorderThickness="1,0,0,0" hc:IconElement.Width="10" hc:IconElement.Height="10"/>
|
<Button Background="{TemplateBinding CloseButtonBackground}" Foreground="{TemplateBinding CloseButtonForeground}" IsTabStop="False" Name="PART_ButtonClose" Height="29" Style="{StaticResource ButtonIcon}" Width="46" hc:IconElement.Geometry="{StaticResource CloseGeometry}" BorderThickness="1,0,0,0" hc:IconElement.Width="10" hc:IconElement.Height="10"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid Grid.Column="0">
|
<Grid Grid.Column="0">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@@ -76,12 +86,7 @@
|
|||||||
<ScrollViewer Grid.Column="1" Grid.Row="0">
|
<ScrollViewer Grid.Column="1" Grid.Row="0">
|
||||||
<TextBlock Margin="10,39,10,10" Text="{TemplateBinding Message}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
<TextBlock Margin="10,39,10,10" Text="{TemplateBinding Message}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Margin="0,10,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Name="PART_Panel" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Margin="0,10,0,16" Orientation="Horizontal" HorizontalAlignment="Center"/>
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsCancel="True" MinWidth="88" Command="interactivity:ControlCommands.Cancel" Content="{ex:Lang Key={x:Static langs:LangKeys.Cancel}}" Margin="5,0"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsDefault="True" MinWidth="88" Command="interactivity:ControlCommands.Confirm" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Margin="5,0" Style="{StaticResource ButtonPrimary}"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsCancel="True" MinWidth="88" Command="interactivity:ControlCommands.No" Content="{ex:Lang Key={x:Static langs:LangKeys.No}}" Margin="5,0"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsDefault="True" MinWidth="88" Command="interactivity:ControlCommands.Yes" Content="{ex:Lang Key={x:Static langs:LangKeys.Yes}}" Margin="5,0" Style="{StaticResource ButtonPrimary}"/>
|
|
||||||
</StackPanel>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
@@ -89,9 +94,9 @@
|
|||||||
<Trigger Property="IsActive" Value="False">
|
<Trigger Property="IsActive" Value="False">
|
||||||
<Setter Property="Opacity" Value=".8" TargetName="ContentPresenterMain"/>
|
<Setter Property="Opacity" Value=".8" TargetName="ContentPresenterMain"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
<Trigger Property="IsMouseOver" Value="True" SourceName="ButtonClose">
|
<Trigger Property="IsMouseOver" Value="True" SourceName="PART_ButtonClose">
|
||||||
<Setter Property="Background" TargetName="ButtonClose" Value="{Binding CloseButtonHoverBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
<Setter Property="Background" TargetName="PART_ButtonClose" Value="{Binding CloseButtonHoverBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||||
<Setter Property="Foreground" TargetName="ButtonClose" Value="{Binding CloseButtonHoverForeground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
<Setter Property="Foreground" TargetName="PART_ButtonClose" Value="{Binding CloseButtonHoverForeground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
</ControlTemplate.Triggers>
|
</ControlTemplate.Triggers>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Media;
|
using System.Media;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
using HandyControl.Interactivity;
|
using HandyControl.Interactivity;
|
||||||
|
using HandyControl.Properties.Langs;
|
||||||
using HandyControl.Tools;
|
using HandyControl.Tools;
|
||||||
|
using HandyControl.Tools.Interop;
|
||||||
|
|
||||||
namespace HandyControl.Controls
|
namespace HandyControl.Controls
|
||||||
{
|
{
|
||||||
@@ -16,10 +19,29 @@ namespace HandyControl.Controls
|
|||||||
/// 消息框
|
/// 消息框
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("ReSharper", "RedundantDelegateCreation")]
|
[SuppressMessage("ReSharper", "RedundantDelegateCreation")]
|
||||||
|
[TemplatePart(Name = ElementPanel, Type = typeof(Panel))]
|
||||||
|
[TemplatePart(Name = ElementButtonClose, Type = typeof(Button))]
|
||||||
|
|
||||||
public sealed class MessageBox : Window
|
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 MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel;
|
||||||
|
|
||||||
|
private Button _buttonOk;
|
||||||
|
|
||||||
|
private Button _buttonCancel;
|
||||||
|
|
||||||
|
private Button _buttonYes;
|
||||||
|
|
||||||
|
private Button _buttonNo;
|
||||||
|
|
||||||
private bool _showOk;
|
private bool _showOk;
|
||||||
|
|
||||||
private bool _showCancel;
|
private bool _showCancel;
|
||||||
@@ -88,9 +110,69 @@ namespace HandyControl.Controls
|
|||||||
}, (s, e) => e.CanExecute = _showNo));
|
}, (s, e) => e.CanExecute = _showNo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnSourceInitialized(EventArgs e)
|
||||||
|
{
|
||||||
|
if (_showYes && !_showCancel)
|
||||||
|
{
|
||||||
|
var hMenu = InteropMethods.GetSystemMenu(this.GetHandle(), false);
|
||||||
|
if (hMenu != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
InteropMethods.EnableMenuItem(hMenu, InteropValues.SC_CLOSE, InteropValues.MF_BYCOMMAND | InteropValues.MF_GRAYED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buttonClose != null)
|
||||||
|
{
|
||||||
|
_buttonClose.IsEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnSourceInitialized(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate();
|
||||||
|
|
||||||
|
_panel = GetTemplateChild(ElementPanel) as Panel;
|
||||||
|
if (_panel != null)
|
||||||
|
{
|
||||||
|
if (_buttonOk != null)
|
||||||
|
{
|
||||||
|
_panel.Children.Add(_buttonOk);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buttonYes != null)
|
||||||
|
{
|
||||||
|
_panel.Children.Add(_buttonYes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buttonNo != null)
|
||||||
|
{
|
||||||
|
_panel.Children.Add(_buttonNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buttonCancel != null)
|
||||||
|
{
|
||||||
|
_panel.Children.Add(_buttonCancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_buttonClose = GetTemplateChild(ElementButtonClose) as Button;
|
||||||
|
if (_buttonClose != null)
|
||||||
|
{
|
||||||
|
_buttonClose.Click += ButtonClose_Click;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonClose_Click(object sender, RoutedEventArgs e) => Close();
|
||||||
|
|
||||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPreviewKeyDown(e);
|
if (e.Key == Key.System && e.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)
|
||||||
{
|
{
|
||||||
@@ -108,22 +190,22 @@ namespace HandyControl.Controls
|
|||||||
builder.Append(Environment.NewLine);
|
builder.Append(Environment.NewLine);
|
||||||
if (_showOk)
|
if (_showOk)
|
||||||
{
|
{
|
||||||
builder.Append(Properties.Langs.Lang.Confirm);
|
builder.Append(Lang.Confirm);
|
||||||
builder.Append(" ");
|
builder.Append(" ");
|
||||||
}
|
}
|
||||||
if (_showYes)
|
if (_showYes)
|
||||||
{
|
{
|
||||||
builder.Append(Properties.Langs.Lang.Yes);
|
builder.Append(Lang.Yes);
|
||||||
builder.Append(" ");
|
builder.Append(" ");
|
||||||
}
|
}
|
||||||
if (_showNo)
|
if (_showNo)
|
||||||
{
|
{
|
||||||
builder.Append(Properties.Langs.Lang.No);
|
builder.Append(Lang.No);
|
||||||
builder.Append(" ");
|
builder.Append(" ");
|
||||||
}
|
}
|
||||||
if (_showCancel)
|
if (_showCancel)
|
||||||
{
|
{
|
||||||
builder.Append(Properties.Langs.Lang.Cancel);
|
builder.Append(Lang.Cancel);
|
||||||
builder.Append(" ");
|
builder.Append(" ");
|
||||||
}
|
}
|
||||||
builder.Append(Environment.NewLine);
|
builder.Append(Environment.NewLine);
|
||||||
@@ -144,7 +226,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||||
messageBox.ShowImage = true;
|
messageBox.ShowImage = true;
|
||||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.SuccessGeometry);
|
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.SuccessGeometry);
|
||||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.SuccessBrush);
|
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.SuccessBrush);
|
||||||
@@ -166,7 +248,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||||
SetImage(messageBox, MessageBoxImage.Information);
|
SetImage(messageBox, MessageBoxImage.Information);
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
messageBox.ShowDialog();
|
messageBox.ShowDialog();
|
||||||
@@ -186,7 +268,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||||
SetImage(messageBox, MessageBoxImage.Warning);
|
SetImage(messageBox, MessageBoxImage.Warning);
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
messageBox.ShowDialog();
|
messageBox.ShowDialog();
|
||||||
@@ -206,7 +288,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||||
SetImage(messageBox, MessageBoxImage.Error);
|
SetImage(messageBox, MessageBoxImage.Error);
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
messageBox.ShowDialog();
|
messageBox.ShowDialog();
|
||||||
@@ -226,7 +308,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
SetButtonStatus(messageBox, MessageBoxButton.OK, MessageBoxResult.OK);
|
||||||
messageBox.ShowImage = true;
|
messageBox.ShowImage = true;
|
||||||
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.FatalGeometry);
|
messageBox.Image = ResourceHelper.GetResource<Geometry>(ResourceToken.FatalGeometry);
|
||||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryTextBrush);
|
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryTextBrush);
|
||||||
@@ -248,7 +330,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
|
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
|
||||||
SetButtonStatus(messageBox, MessageBoxButton.OKCancel);
|
SetButtonStatus(messageBox, MessageBoxButton.OKCancel, MessageBoxResult.Cancel);
|
||||||
SetImage(messageBox, MessageBoxImage.Question);
|
SetImage(messageBox, MessageBoxImage.Question);
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
messageBox.ShowDialog();
|
messageBox.ShowDialog();
|
||||||
@@ -268,7 +350,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(null, info.Message, info.Caption, info.Button, MessageBoxImage.None, info.DefaultResult);
|
messageBox = CreateMessageBox(null, info.Message, info.Caption, info.Button, MessageBoxImage.None, info.DefaultResult);
|
||||||
SetButtonStatus(messageBox, info.Button);
|
SetButtonStatus(messageBox, info.Button, info.DefaultResult);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.IconKey))
|
if (!string.IsNullOrEmpty(info.IconKey))
|
||||||
{
|
{
|
||||||
@@ -318,7 +400,7 @@ namespace HandyControl.Controls
|
|||||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
messageBox = CreateMessageBox(owner, messageBoxText, caption, button, icon, defaultResult);
|
messageBox = CreateMessageBox(owner, messageBoxText, caption, button, icon, defaultResult);
|
||||||
SetButtonStatus(messageBox, button);
|
SetButtonStatus(messageBox, button, defaultResult);
|
||||||
SetImage(messageBox, icon);
|
SetImage(messageBox, icon);
|
||||||
SystemSounds.Asterisk.Play();
|
SystemSounds.Asterisk.Play();
|
||||||
messageBox.ShowDialog();
|
messageBox.ShowDialog();
|
||||||
@@ -363,25 +445,126 @@ namespace HandyControl.Controls
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton messageBoxButton)
|
private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton messageBoxButton, MessageBoxResult defaultResult)
|
||||||
{
|
{
|
||||||
switch (messageBoxButton)
|
switch (messageBoxButton)
|
||||||
{
|
{
|
||||||
case MessageBoxButton.OK:
|
case MessageBoxButton.OK:
|
||||||
messageBox._showOk = true;
|
messageBox._showOk = true;
|
||||||
|
messageBox._buttonOk = new Button
|
||||||
|
{
|
||||||
|
IsCancel = true,
|
||||||
|
IsDefault = true,
|
||||||
|
Content = Lang.Confirm,
|
||||||
|
Command = ControlCommands.Confirm,
|
||||||
|
Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle")
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MessageBoxButton.OKCancel:
|
case MessageBoxButton.OKCancel:
|
||||||
messageBox._showOk = true;
|
messageBox._showOk = true;
|
||||||
|
messageBox._buttonOk = new Button
|
||||||
|
{
|
||||||
|
Content = Lang.Confirm,
|
||||||
|
Command = ControlCommands.Confirm
|
||||||
|
};
|
||||||
|
|
||||||
messageBox._showCancel = true;
|
messageBox._showCancel = true;
|
||||||
|
messageBox._buttonCancel = new Button
|
||||||
|
{
|
||||||
|
IsCancel = true,
|
||||||
|
Content = Lang.Cancel,
|
||||||
|
Command = ControlCommands.Cancel
|
||||||
|
};
|
||||||
|
|
||||||
|
if (defaultResult == MessageBoxResult.Cancel)
|
||||||
|
{
|
||||||
|
messageBox._buttonOk.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonCancel.IsDefault = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageBox._buttonOk.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonOk.IsDefault = true;
|
||||||
|
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MessageBoxButton.YesNo:
|
case MessageBoxButton.YesNo:
|
||||||
messageBox._showYes = true;
|
messageBox._showYes = true;
|
||||||
|
messageBox._buttonYes = new Button
|
||||||
|
{
|
||||||
|
Content = Lang.Yes,
|
||||||
|
Command = ControlCommands.Yes
|
||||||
|
};
|
||||||
|
|
||||||
messageBox._showNo = true;
|
messageBox._showNo = true;
|
||||||
|
messageBox._buttonNo = new Button
|
||||||
|
{
|
||||||
|
Content = Lang.No,
|
||||||
|
Command = ControlCommands.No
|
||||||
|
};
|
||||||
|
|
||||||
|
if (defaultResult == MessageBoxResult.No)
|
||||||
|
{
|
||||||
|
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonNo.IsDefault = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonYes.IsDefault = true;
|
||||||
|
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MessageBoxButton.YesNoCancel:
|
case MessageBoxButton.YesNoCancel:
|
||||||
messageBox._showYes = true;
|
messageBox._showYes = true;
|
||||||
|
messageBox._buttonYes = new Button
|
||||||
|
{
|
||||||
|
Content = Lang.Yes,
|
||||||
|
Command = ControlCommands.Yes
|
||||||
|
};
|
||||||
|
|
||||||
messageBox._showNo = true;
|
messageBox._showNo = true;
|
||||||
|
messageBox._buttonNo = new Button
|
||||||
|
{
|
||||||
|
Content = Lang.No,
|
||||||
|
Command = ControlCommands.No
|
||||||
|
};
|
||||||
|
|
||||||
messageBox._showCancel = true;
|
messageBox._showCancel = true;
|
||||||
|
messageBox._buttonCancel = new Button
|
||||||
|
{
|
||||||
|
IsCancel = true,
|
||||||
|
Content = Lang.Cancel,
|
||||||
|
Command = ControlCommands.Cancel
|
||||||
|
};
|
||||||
|
|
||||||
|
if (defaultResult == MessageBoxResult.No)
|
||||||
|
{
|
||||||
|
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonNo.IsDefault = true;
|
||||||
|
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
}
|
||||||
|
else if (defaultResult == MessageBoxResult.Cancel)
|
||||||
|
{
|
||||||
|
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonCancel.IsDefault = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageBox._buttonYes.Style = ResourceHelper.GetResource<Style>("MessageBoxPrimaryButtonStyle");
|
||||||
|
messageBox._buttonYes.IsDefault = true;
|
||||||
|
messageBox._buttonNo.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
messageBox._buttonCancel.Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:hc="clr-namespace:HandyControl.Controls"
|
xmlns:hc="clr-namespace:HandyControl.Controls"
|
||||||
xmlns:langs="clr-namespace:HandyControl.Properties.Langs"
|
|
||||||
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
|
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
|
||||||
xmlns:ex="clr-namespace:HandyControl.Tools.Extension"
|
|
||||||
xmlns:themes="clr-namespace:HandyControl.Themes">
|
xmlns:themes="clr-namespace:HandyControl.Themes">
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Window.xaml"/>
|
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Window.xaml"/>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
<Style x:Key="MessageBoxButtonStyle" BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
|
||||||
|
<Setter Property="MinWidth" Value="88"/>
|
||||||
|
<Setter Property="Visibility" Value="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}"/>
|
||||||
|
<Setter Property="Margin" Value="5,0"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="MessageBoxPrimaryButtonStyle" BasedOn="{StaticResource ButtonPrimary}" TargetType="Button">
|
||||||
|
<Setter Property="MinWidth" Value="88"/>
|
||||||
|
<Setter Property="Visibility" Value="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}"/>
|
||||||
|
<Setter Property="Margin" Value="5,0"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
<Style TargetType="hc:MessageBox" BasedOn="{StaticResource WindowWin10}">
|
<Style TargetType="hc:MessageBox" BasedOn="{StaticResource WindowWin10}">
|
||||||
<Setter Property="MinHeight" Value="172"/>
|
<Setter Property="MinHeight" Value="172"/>
|
||||||
<Setter Property="ShowInTaskbar" Value="False"/>
|
<Setter Property="ShowInTaskbar" Value="False"/>
|
||||||
@@ -33,7 +43,7 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<StackPanel WindowChrome.IsHitTestVisibleInChrome="True" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
<StackPanel WindowChrome.IsHitTestVisibleInChrome="True" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||||
<Button Background="{TemplateBinding CloseButtonBackground}" Foreground="{TemplateBinding CloseButtonForeground}" Command="SystemCommands.CloseWindowCommand" IsTabStop="False" Name="ButtonClose" Height="29" Style="{StaticResource ButtonIcon}" Width="46" hc:IconElement.Geometry="{StaticResource CloseGeometry}" BorderThickness="1,0,0,0" hc:IconElement.Width="10" hc:IconElement.Height="10"/>
|
<Button Background="{TemplateBinding CloseButtonBackground}" Foreground="{TemplateBinding CloseButtonForeground}" IsTabStop="False" Name="PART_ButtonClose" Height="29" Style="{StaticResource ButtonIcon}" Width="46" hc:IconElement.Geometry="{StaticResource CloseGeometry}" BorderThickness="1,0,0,0" hc:IconElement.Width="10" hc:IconElement.Height="10"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid Grid.Column="0">
|
<Grid Grid.Column="0">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@@ -75,12 +85,7 @@
|
|||||||
<ScrollViewer Grid.Column="1" Grid.Row="0">
|
<ScrollViewer Grid.Column="1" Grid.Row="0">
|
||||||
<TextBlock Margin="10,39,10,10" Text="{TemplateBinding Message}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
<TextBlock Margin="10,39,10,10" Text="{TemplateBinding Message}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Margin="0,10,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Name="PART_Panel" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Margin="0,10,0,16" Orientation="Horizontal" HorizontalAlignment="Center"/>
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsCancel="True" MinWidth="88" Command="interactivity:ControlCommands.Cancel" Content="{ex:Lang Key={x:Static langs:LangKeys.Cancel}}" Margin="5,0"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsDefault="True" MinWidth="88" Command="interactivity:ControlCommands.Confirm" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Margin="5,0" Style="{StaticResource ButtonPrimary}"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsCancel="True" MinWidth="88" Command="interactivity:ControlCommands.No" Content="{ex:Lang Key={x:Static langs:LangKeys.No}}" Margin="5,0"/>
|
|
||||||
<Button Visibility="{Binding IsEnabled,RelativeSource={RelativeSource Self},Converter={StaticResource Boolean2VisibilityConverter}}" IsDefault="True" MinWidth="88" Command="interactivity:ControlCommands.Yes" Content="{ex:Lang Key={x:Static langs:LangKeys.Yes}}" Margin="5,0" Style="{StaticResource ButtonPrimary}"/>
|
|
||||||
</StackPanel>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
@@ -88,9 +93,9 @@
|
|||||||
<Trigger Property="IsActive" Value="False">
|
<Trigger Property="IsActive" Value="False">
|
||||||
<Setter Property="Opacity" Value=".8" TargetName="ContentPresenterMain"/>
|
<Setter Property="Opacity" Value=".8" TargetName="ContentPresenterMain"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
<Trigger Property="IsMouseOver" Value="True" SourceName="ButtonClose">
|
<Trigger Property="IsMouseOver" Value="True" SourceName="PART_ButtonClose">
|
||||||
<Setter Property="Background" TargetName="ButtonClose" Value="{Binding CloseButtonHoverBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
<Setter Property="Background" TargetName="PART_ButtonClose" Value="{Binding CloseButtonHoverBackground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||||
<Setter Property="Foreground" TargetName="ButtonClose" Value="{Binding CloseButtonHoverForeground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
<Setter Property="Foreground" TargetName="PART_ButtonClose" Value="{Binding CloseButtonHoverForeground,RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
</ControlTemplate.Triggers>
|
</ControlTemplate.Triggers>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ namespace HandyControl.Tools.Interop
|
|||||||
[DllImport(InteropValues.ExternDll.User32)]
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
internal static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
internal static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||||
|
|
||||||
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
|
internal static extern bool EnableMenuItem(IntPtr hMenu, int UIDEnabledItem, int uEnable);
|
||||||
|
|
||||||
[DllImport(InteropValues.ExternDll.User32)]
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
internal static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
internal static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,9 @@ namespace HandyControl.Tools.Interop
|
|||||||
WM_CLIPBOARDUPDATE = 0x031D,
|
WM_CLIPBOARDUPDATE = 0x031D,
|
||||||
WM_USER = 0x0400,
|
WM_USER = 0x0400,
|
||||||
WS_VISIBLE = 0x10000000,
|
WS_VISIBLE = 0x10000000,
|
||||||
|
MF_BYCOMMAND = 0x00000000,
|
||||||
MF_BYPOSITION = 0x400,
|
MF_BYPOSITION = 0x400,
|
||||||
|
MF_GRAYED = 0x00000001,
|
||||||
MF_SEPARATOR = 0x800,
|
MF_SEPARATOR = 0x800,
|
||||||
TB_GETBUTTON = WM_USER + 23,
|
TB_GETBUTTON = WM_USER + 23,
|
||||||
TB_BUTTONCOUNT = WM_USER + 24,
|
TB_BUTTONCOUNT = WM_USER + 24,
|
||||||
@@ -82,6 +84,7 @@ namespace HandyControl.Tools.Interop
|
|||||||
DESKTOPVERTRES = 117,
|
DESKTOPVERTRES = 117,
|
||||||
LOGPIXELSX = 88,
|
LOGPIXELSX = 88,
|
||||||
LOGPIXELSY = 90,
|
LOGPIXELSY = 90,
|
||||||
|
SC_CLOSE = 0xF060,
|
||||||
SC_SIZE = 0xF000,
|
SC_SIZE = 0xF000,
|
||||||
SC_MOVE = 0xF010,
|
SC_MOVE = 0xF010,
|
||||||
SC_MINIMIZE = 0xF020,
|
SC_MINIMIZE = 0xF020,
|
||||||
|
|||||||
Reference in new issue
Block a user