如何获得以下样式的消息框非常好?该MessageBox function似乎不能做的伎俩如何在WPF中为消息框设置不同样式的字体
2
A
回答
2
您可以使用窗口
这里让自己的通知对话框是一个简单的例子我刚掀起一起
用法:
NotificationDialog.ShowNotification("Backup and Restor center"
, "You need to be an Administrator to run backup"
, "Use Fast User Switching to switch to an account with administrator privileges, or log off and log on as an administrator"
, NotifyIcon.Exclamation);
代码:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace WpfApplication8
{
/// <summary>
/// Interaction logic for NotificationDialog.xaml
/// </summary>
public partial class NotificationDialog : Window, INotifyPropertyChanged
{
public static void ShowNotification(string title, string caption, string message, NotifyIcon icon)
{
NotificationDialog dialog = new NotificationDialog();
dialog.Title = title;
dialog.Caption = caption;
dialog.Message = message;
dialog.Image = dialog.GetIcon(icon);
dialog.ShowDialog();
}
private string _caption;
private string _message;
private BitmapSource _image;
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
public NotificationDialog()
{
DataContext = this;
InitializeComponent();
Loaded += (s, e) =>
{
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
};
}
public string Caption
{
get { return _caption; }
set { _caption = value; NotifyPropertyChanged(); }
}
public string Message
{
get { return _message; }
set { _message = value; NotifyPropertyChanged(); }
}
public BitmapSource Image
{
get { return _image; }
set { _image = value; NotifyPropertyChanged(); }
}
private BitmapSource GetIcon(NotifyIcon iconType)
{
Icon icon = (Icon)typeof(SystemIcons).GetProperty(iconType.ToString(), BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
private void Button_Close_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName]string propertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public enum NotifyIcon
{
Application,
Asterisk,
Error,
Exclamation,
Hand,
Information,
Question,
Shield,
Warning,
WinLogo
}
}
的XAML:
<Window x:Class="WpfApplication8.NotificationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="239" Width="417" Title="{Binding Title}" ResizeMode="NoResize" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="223*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Content="Close" HorizontalAlignment="Right" Margin="0,0,10,7" Grid.Row="1" VerticalAlignment="Bottom" Width="75" Click="Button_Close_Click"/>
<StackPanel Margin="70,10,10,0">
<TextBlock Text="{Binding Caption}" FontSize="20" Foreground="DarkBlue" TextWrapping="Wrap"/>
<TextBlock Margin="0,10,0,0" Text="{Binding Message}" TextWrapping="Wrap"/>
</StackPanel>
<Image Source="{Binding Image}" Stretch="None" HorizontalAlignment="Left" Height="52" Margin="6,10,0,0" VerticalAlignment="Top" Width="55"/>
</Grid>
</Window>
结果:
0
我不认为这是对这种风格正式框架的支持,但对于建筑的消息框状的准则(包括该截图中使用的特定字体)在这里:User Interface Text。
另请参见此CodeProject文章:WPF TaskDialog Wrapper and Emulator。显然,它使用本地Windows 7调用来生成正确的样式。
相关问题
- 1. 如何设置字体样式在FPDF
- 2. 如何在WPF Window.Resources中设置样式。
- 3. 如何设置WebView的字体样式?
- 4. 如何在WPF DataGrid中设置组合框的样式?
- 5. 如何在Android中设置自定义不同的字体样式
- 6. WPF:如何在一个样式类中设置DataGridTextColumn的样式?
- 7. Wpf样式:在列表框中设置样式
- 8. WPF如何在RadioButton上设置样式?
- 9. 如何为后备字体设置不同的字体重量?
- 10. toolStripComboBox设置字体样式?
- 11. 为RTF文档设置字体样式
- 12. 如何在wpf中创建消息框
- 13. 如何为不同的textareas设置不同的字体颜色
- 14. 在Blend中设置WPF中的样式列表框
- 15. 如何为WPF中的多个TabItem设置一种样式?
- 16. 如何在WPF中为文本框和组合框应用相同的样式?
- 17. WPF消息框与WinForms的消息框
- 18. 如何设置粗体样式的自定义字体
- 19. 为文本框中的不同行设置不同的字体大小
- 20. 如何在运行时在wpf中设置gridview行的样式?
- 21. 在WPF中使用IDataErrorInfo设置文本框的样式
- 22. 如何在CSS中设置不同标题(h1,h2,...)的样式?
- 23. 如何设置tkinter消息边框
- 24. 如何设置样式或字体为TextView的文本在android中?
- 25. 在WPF中设置样式TargetType
- 26. 如何在QComboBox的第一项上设置字体样式?
- 27. 消息框上的不同消息
- 28. 如何设置UITextfield的边框样式
- 29. WPF - 自定义消息框的样式在扩展WPF工具包
- 30. 如何在wpf中设置按钮样式的Data属性?
只需从一个窗口制作一个。 –