0
votes

If the StackPanel contains controls of several types (e.g. ComboBox, CheckBox, Grid), when applying margin or padding styles, is it possible in XAML to express the concept "all of the items you contain" or "each of the items your contain" and apply the style to the StackPanel itself, or must each control be explicity referenced by its type as below? Is there a way to say TargetType=ANY?

<StackPanel>
   <StackPanel.Resources>
     <Style TargetType="{x:Type foo:ComboBox}">
         <Setter Property="Margin" Value="10,10,10,10"/>
     </Style>
     <Style TargetType="{x:Type foo:CheckBox}">
         <Setter Property="Margin" Value="10,10,10,10"/>
     </Style>
      <Style TargetType="{x:Type foo:GridView}">
         <Setter Property="Margin" Value="10,10,10,10"/>
     </Style>
</StackPanel.Resources>
1
yes, target the style to a base type, such as controldenis morozov

1 Answers

0
votes
<StackPanel>
    <StackPanel.Resources>
        <Style TargetType="{x:Type Control}">
            <Style.Setters>
                <Setter Property="Margin" Value="5"/>
            </Style.Setters>
        </Style>
    </StackPanel.Resources>
    <ComboBox />
    <Label />
    <ListView />