Is it possible to define a ResourceDictionary in a style?
For example, suppose I wanted to have two different styles for StackPanels, and in one I want all the buttons to be blue and the other I want them to be red. Is it possible?
Something like
<Style x:Key="RedButtonsPanel" TargetType="{x:Type StackPanel}"> <Setter Property="Orientation" Value="Horizontal" /> <Setter Property="StackPanel.Resources"> <Setter.Value> <ResourceDictionary> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="Red" /> </Style> </ResourceDictionary> </Setter.Value> </Setter> </Style>
The above code crashes with an error about the value of the Setter property cannot be zero (although it is clearly not equal to zero).
I can do something like
<ResourceDictionary x:Key="RedButtons"> <Style TargetType="{x:Type Button}"> <Setter Property="Width" Value="100" /> <Setter Property="Background" Value="Red" /> </Style> </ResourceDictionary> <StackPanel Resources={StaticResource RedButtons} />
However, I was wondering if there is a way to combine ResourceDictionary into a style.
styles wpf xaml resourcedictionary
Rachel
source share