WPF style for panel/border with triggers for children/parent?
Is it possible in XAML to
- Define a style for panel that creates a border for each panel?
- Change the style of an ancestor item (i.e. the border background) when an item or it's child is selected?
i.e.
<StackPanel Style="{StaticResource WidgetStyle}">
<Label />
<Butto开发者_Go百科n />
<StackPanel>
<ListView />
</StackPanel>
</StackPanel>
I would like to have WidgetStyle define a (rounded) border and change the border color, e.g. if the ListView or Button is selected.
Thanks!
I'm afraid the answer to your first question is no! You cannot template Panel controls, they are lookless. What you could do in this. There are a few options, such as create a custom control that include a StackPanel. The answe to this question includes quite a few good ideas:
Changing WPF StackPanel template
For your second question, again no, you cannot style an ancestor based on a style change in a child by styling alone.
You could use ElementName binding to connect some properties of the elements together:
<Border Background={Binding ElementName=MyButton, Path=Tag>>
<StackPanel Style="{StaticResource WidgetStyle}">
<Label />
<Button x:Name="MyButton"/>
<StackPanel>
<ListView />
</StackPanel>
</StackPanel>
</Border>
In the above, the border background is bound to the Tag property of the button 'MyButton' you can then apply a style to the button which sets the Tag property and will thus change the border background.
精彩评论