首页 > 解决方案 > 设置 showdialog 设置的图标

问题描述

有没有办法将图标添加到对话框。

这是我为对话框创建设置的地方:

dynamic settings = new ExpandoObject();
settings.WindowStartupLocation = 
WindowStartupLocation.CenterOwner;
settings.WindowStyle = WindowStyle.SingleBorderWindow;
settings.ResizeMode = ResizeMode.NoResize;
settings.Title = "System Error";
//settings.(set my icon here);
status.UpdateMessage(ex.Message, $"{ex.Message} To the products list");
_window.ShowDialog(_status, null, settings);

标签: c#wpfshowdialog

解决方案


我假设我们正在谈论标题栏最左侧的图标。

一种方法是这样的(在您的 ExpandoObject 构造函数中):

Uri iconUri = new Uri("PathToYourIcon");
Icon = BitmapFrame.Create(iconUri);

有关更多详细信息,请参阅:如何在 wpf 中的代码中设置窗口图标?

您还应该能够在 XAML 模板中设置 Window 的 Icon 属性。毕竟,对话框应该只是一个窗口,就像任何其他窗口一样。


推荐阅读