是否可以在ModernUI对话框中添加一个窗口按钮("关闭"," Min"," Max")?
ModernDialog.ShowMessage("Dialog", "How to add window Buttons?");
我找不到任何信息。
答案 0 :(得分:0)
默认情况下,对话框是模态的。你不应该使用min / max。对话框上的操作按钮将执行关闭功能。
那就是说,我最近实现了自己的DialogHelper
,你可以适应:
public enum MessageType
{
None = 0,
Error = 16,
Stop = Error,
Hand = Error,
Question = 32,
Warning = 48,
Exclamation = Warning,
Information = 64,
Asterisk = Information
}
public static class DialogHelper
{
public static bool? ShowMessage(string text, string title, MessageType messageType = MessageType.None)
{
var dlg = new ModernDialog();
dlg.Buttons = new[] {dlg.OkButton};
dlg.Title = title;
dlg.Content = text;
dlg.BackgroundContent = new DialogBackgroundContent(messageType);
dlg.MinWidth = dlg.MinWidth + 200;
bool? res = false;
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => res = dlg.ShowDialog()));
return res;
}
}
我这样做主要是为了抽象出现代用户界面框架,以防我以后想换掉其他东西。
DialogBackgroundContent
只是一个XAML UserControl我用来装饰成功/失败图标的背景。
<UserControl x:Class="Cmc.Installer.Core.Controls.DialogBackgroundContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Path x:Name="SuccessIcon" Width="32" Height="32" Stretch="Fill" Fill="#FF00FF00"
Margin="0,32,32,0"
HorizontalAlignment="Right" VerticalAlignment="Top"
Data="M-150.204,626.126C-152.317,626.126 -154.429,626.126 -156.541,626.126 -167.642,633.42 -180.629,646.047 -189.668,657.238 -190.916,658.782 -192.945,662.362 -193.701,662.422 -194.041,662.448 -198.024,659.719 -198.614,659.297 -202.818,656.279 -205.779,653.709 -209.257,650.899 -211.248,652.172 -212.879,653.805 -214.153,655.797 -206.627,665.074 -200.283,675.534 -193.124,685.18 -181.491,665.11 -168.473,644.683 -152.796,629.006 -151.735,627.946 -149.817,626.933 -150.204,626.126z"/>
<Path x:Name="FailureIcon" Visibility="Hidden" Width="32" Height="32" Stretch="Fill" Fill="#FFFF0000"
Margin="0,32,32,0"
HorizontalAlignment="Right" VerticalAlignment="Top"
Data="M50,5C25.147,5,5,25.147,5,50c0,24.853,20.147,45,45,45s45-20.147,45-45C95,25.147,74.853,5,50,5z M55,75H45V65h10V75z M55,60H45V25h10V60z"/>
</Grid>
</UserControl>
public partial class DialogBackgroundContent : UserControl
{
public DialogBackgroundContent(MessageType messageType = MessageType.None)
{
InitializeComponent();
switch (messageType)
{
case MessageType.None:
FailureIcon.Visibility = Visibility.Hidden;
SuccessIcon.Visibility = Visibility.Hidden;
break;
case MessageType.Error:
FailureIcon.Visibility = Visibility.Visible;
SuccessIcon.Visibility = Visibility.Hidden;
break;
case MessageType.Question:
break;
case MessageType.Warning:
break;
case MessageType.Information:
FailureIcon.Visibility = Visibility.Hidden;
SuccessIcon.Visibility = Visibility.Visible;
break;
default:
throw new ArgumentOutOfRangeException("messageType");
}
}
}
您可能需要尝试在我的函数中替换ModernDialog
ModernWindow
以获得更大的灵活性。
ModernWindow
:https://github.com/firstfloorsoftware/mui/blob/master/1.0/FirstFloor.ModernUI/Shared/Windows/Controls/ModernWindow.cs