Reputation: 45096
Want to match the default background color of a button for use in an Expander.
What is the default background color of a button?
What have I tried to far?
A lot of different colors but did not find a match.
Upvotes: 6
Views: 17283
Reputation: 1799
Blam's answer works but is a "dynamic reference to the control system brush", so in my case because my button is nested into a stackpanel that starts out disabled, when I used Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
, it caused my button to be a flat gray even when the stackpanel (and therefore button) were enabled. Apparently it dynamically set my button to the "disabled gray" color, but doesn't dynamically change it to the full color mode when enabled.
As my link says, you can get a static reference to the button using:
Background="{DynamicResource {x:Static SystemColors.ControlBrush}}"
Note the only difference is using ControlBrush
instead of ControlBrushKey
. Doing this allowed my button to start out flat gray when disabled, but was full color when enabled.
Upvotes: 0
Reputation: 45096
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
Upvotes: 18
Reputation: 1526
Here are the predefined brushes that wpf controls are using
You will still need to find which one is used by the Button control, you can do that by editing the Button template with Blend.
Depending on the case you might need to reference the brush as
"{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"
or whatever the brush is.
Edit1: If I'm not mistaken the WindowBrush resource is the one used by the Button control for its default background.
Edit2 Don't forget that the default Button template also contains a chrome object that adds some impact on the final layout.
Upvotes: 4
Reputation: 9224
In WPF you can right click on an element and select "Edit Template", this will create the exact template that control is using including background color. You can then apply the same generated background color to whatever control you want.
Alternatively, you can go to that controls brush properties and click on the little square and select "Convert to new resource" if you're just looking to replicate a single brush. Then apply that newly generated brush to whatever element you want.
Resulting in the following
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<LinearGradientBrush x:Key="Brush1" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.5"/>
<GradientStop Color="#FFDDDDDD" Offset="0.5"/>
<GradientStop Color="#FFCDCDCD" Offset="1"/>
</LinearGradientBrush>
</Window.Resources>
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="151,139,0,0" VerticalAlignment="Top" Width="75" Background="{DynamicResource Brush1}"/>
<Expander Header="Expander" HorizontalAlignment="Left" Margin="412,129,0,0" VerticalAlignment="Top" Background="{DynamicResource Brush1}">
<Grid Background="#FFE5E5E5"/>
</Expander>
</Grid>
Upvotes: 7
Reputation: 3905
The WPF will apply different the colors/shapes depending on the operating system. So, there isn't exactly one default color. But, as for reference, check the button controltemplate page. You should find the static resources WindowBackgroundBrush, DisabledBackgroundBrush and SelectedBackgroundBrush
Upvotes: 2
Reputation: 393
you could use 'Colour to Html' it's a nice application and you have a tool to extract any color from you desktop Colour to Html
Upvotes: 0