tags:

views:

16

answers:

1

This is my XAML fragment:

<StackPanel Orientation="Horizontal" >
    <CheckBox Content="Sunday" IsChecked="{Binding Sunday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Monday" IsChecked="{Binding Monday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Tuesday" IsChecked="{Binding Tuesday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Wednesday" IsChecked="{Binding Wednesday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Thursday" IsChecked="{Binding Thursday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Friday" IsChecked="{Binding Friday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
    <CheckBox Content="Saturday" IsChecked="{Binding Saturday}"  Style="{StaticResource ResourceKey=GridChecks}"/>
</StackPanel>

Instead of constantly repeating myself, is there a way to say "All the checkboxes under the stack panel get the GridChecks style"?

+4  A: 
<StackPanel>
   <StackPanel.Resources>
      <Style TargetType={x:Type CheckBox}>
      <!--define your checkbox style here-->
      </Style>
   </StackPanel.Resources>

   <!--these checkboxes will have defined style described in StackPanel.Resources-->
   <CheckBox Content="First"/>
   <CheckBox Content="Second"/>
   <CheckBox Content="Third"/>
</StackPanel>
Eugene Cheverda