Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background color of button in WPF?

How to set the background color of a button in xaml?

It can't be much harder than

<Button Margin="2" Background ="LightGreen" ....>

But this does not work...for the avoidance of confusion, button here is System.Windows.Controls.Button

Edit

I forgot to mention that I use DevExpress's ThemeManager but did not think that would cause issues as per DevExpress they do not style the standard Windows Buttons...apparently they do, however, which basically makes it impossible to change the background color of a button without some major work...

like image 808
Matt Avatar asked Jan 29 '26 14:01

Matt


1 Answers

According to documentation:

DevExpress provides multiple themes that can be applied to all DevExpress controls for WPF and some standard controls (GroupBox, ScrollViewer, Scroll, RadoiButton, Button, ListBox, Slider, TabControl, Separator, ToggleButton, RepeatButton, Label, ListBoxItem, TabItem, ToolTip, etc).

As you can see the Button control is listed here. But then in documentation it is said that you can disable theme of individual control by setting ThemeName attribute to None. So, you can just disable the theme for button or for some of its parent containers and use your own style.
Here is example:

<Button Margin="2" Background="LightGreen" dx:ThemeManager.ThemeName="None" ...>
like image 194
nempoBu4 Avatar answered Jan 31 '26 04:01

nempoBu4