Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Style for a StackPanel and its Contents

I want to create a style for Stackpanels using a key. This style will be in a global ResourceDictionary for use everywhere in the application. But it should not only set the style of the Stackpanel, but also its content.

I want to use the stackpanel like this:

<StackPanel Style="{StaticResource GlobalStackPanelStyle}">
<Button>test</Button> <-- the button style should also be defined due to the Stackpanel style
</StackPanel>

How should the Resourcedictionary look like if for example all the containing buttons should be green?

like image 683
marty bourque Avatar asked Feb 14 '23 12:02

marty bourque


1 Answers

You would have something like this in your resource dictionary:

<Style TargetType="StackPanel" x:Key="GlobalStackPanelStyle">
   <Style.Resources>
        <Style TargetType="Button">
            <Setter Property="Background" Value="Green" />
        </Style>
    </Style.Resources>
</Style>
like image 60
Ming Slogar Avatar answered Feb 19 '23 19:02

Ming Slogar