WPF: Can I apply the same style to mulitple items at once?
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=GridCh开发者_开发问答ecks}"/>
<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"?
<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>
精彩评论