I'm creating a style that targets a button. The buttons that the style will be applied against have an image and a textblock in a stack panel inside of them. I'm looking to use a trigger to affect the properties of the child controls based upon certain condtions.
I would like to use the button style to be able to affect the stackpanels orientation as well as the image's defined width.
I've looked throught the various child control types that are available in the property intellisence of the style setter... I can see things like Grid, DockPanel and TextBlock... but the ones that I'm looking for are very noticable in their absence.
Is there a reason when I can't affect certain child control types? Is there any way to do so without rolling a custom control which explicitly exposes the child control properties that I'm looking to affect?
You can use implicit styles:
<Style TargetType="Button" x:Key="myButtonStyle"> <!-- Has a key, will only be applied on elements that have their style set to {StaticResource myButtonStyle} -->
<Setter Property="Background" Value="Green" />
...
<Style.Resources>
<Style TargetType="Image"> <!-- No key, so it is implicit and will apply to any child element of type Image -->
<Setter Property="Height" Value="20" />
...
</Style>
</Style.Resources>
</Style>
Of course you can add triggers as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With