How to set a flat style to Button and ComboBox in WPF

In XAML:

1
2
3
4
5
6
7
8
9
<Button
   Name="myComboBox"
   Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
/>
 
<ComboBox
   Name="myButton"
   Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
/>
<Button
   Name="myComboBox"
   Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
/>

<ComboBox
   Name="myButton"
   Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
/>

In code (C#):

1
2
3
4
5
myButton.Style =
    (Style)FindResource(ToolBar.ButtonStyleKey);
 
myComboBox.Style = (Style)FindResource(ToolBar.ComboBoxStyleKey);
myComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
myButton.Style =
    (Style)FindResource(ToolBar.ButtonStyleKey);

myComboBox.Style = (Style)FindResource(ToolBar.ComboBoxStyleKey);
myComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

Leave a comment

Your email address will not be published. Required fields are marked *