在代码后面设置按钮样式

dan*_*iel 3 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;
Run Code Online (Sandbox Code Playgroud)

我得到错误

System.Windows.Markup.XamlParseException: ''System.Drawing.SolidBrush' is not a valid value for the 'System.Windows.Documents.TextElement.Foreground' property on a Setter.'
Run Code Online (Sandbox Code Playgroud)

gre*_*k40 5

确保使用WPF库,而不是WindowsForms或GDI +库。

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

您当前使用的是System.Drawing.Brushes和System.Drawing.SolidBrush。