c# - 在后台代码中设置按钮样式

标签 c# wpf xceed

如何设置按钮的样式?我使用 Xceed.wpf.toolkit

 Xceed.Wpf.Toolkit.MessageBox mbox = new Xceed.Wpf.Toolkit.MessageBox();
 System.Windows.Style style = new System.Windows.Style(typeof(System.Windows.Controls.Button));
 style.Setters.Add( new System.Windows.Setter(System.Windows.Controls.Button.ForegroundProperty, Brushes.DarkGreen));
 mbox.OkButtonStyle = style;

我得到了错误

System.Windows.Markup.XamlParseException: ''System.Drawing.SolidBrush' is not a valid value for the 'System.Windows.Documents.TextElement.Foreground' property on a Setter.'

最佳答案

一定要使用 WPF 库而不是 WindowsForms 或 GDI+ 库...

您应该使用什么:System.Windows.Media.Brushes,其中包含 DarkGreen 作为 System.Windows.Media.SolidColorBrush(在 PresentationCore 中.dll)。

您当前使用的是 System.Drawing.BrushesSystem.Drawing.SolidBrush

关于c# - 在后台代码中设置按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43474507/

相关文章:

c# - 如何在 C# 中调用 async void 事件处理程序?

C# 调用一个函数?

wpf - 使用Xceed PropertyGrid

c# - WPF AvalonDock LayoutChanged 和 LayoutChanging MVVM

c# - Automapper 更新字典值

c# - Facebook/Google/Twitter 记住登录信息

wpf - 创建一个允许缩放和平移的 WPF 窗口

c# - ObservableCollection PropertyChanged 事件

c# - 从 DataGrid WPF C# 中的选定行获取特定单元格的数据

wpf - 无法设置 CheckComboBox 中所选项目的初始状态