I have a stack panel with a few (different) items:
<StackPanel ...>
<TextBlock ... />
<CheckBox ... />
<CheckBox ... />
<Button ... />
</StackPanel>
I would like to apply VerticalAlignment="Center"
to all children of the StackPanel without having to add VerticalAlignent="Center"
or Style=...
to every single child. So, I guess I want to define an implicit style which applies to the TextBlock, the CheckBoxes and the Button.
I tried adding a <Style TargetType="FrameworkElement">
in the stack panel's resources, but (obviously) this doesn't work, since the TargetType creates an implicit x:Key of {x:Type FrameworkElement}
, whereas TextBlock only automatically binds to Styles with an x:Key of {x:Type TextBlock}
.
So, as far as I can see, the only options I have are: (1) create three Styles for all three types in the stack panel's resources, (2) create one style and manually bind it to all children, (3) manually set the VerticalAlignment
option at all children. What I want is: (4) Create one Style and automatically bind it to all children of the stack panel. Is that possible? Or is there some other solution that is less redundant than (1)-(3)?