wpf, Style, Setters
I've got question about wpf xaml style definitions. When I try to set style in this way:
<StackPanel Orientation="Vertical">
<StackPanel.Style>
<Setter Property="BusinessModeler:Gr开发者_运维问答aphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
</StackPanel.Style>
</StackPanel>
raises exception with message - 'System.Windows.Setter' is not a valid value for property 'Style'
.
when I use this definition:
<Style x:Key="itemBehaviour" >
<Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
</Style>
<StackPanel Orientation="Vertical" Style="{StaticResource itemBehaviour}">
everything works fine.
So, what is the difference?
StackPanel.Style
is a property of type Style
, so without wrapping the Setter
in <Style></Style>
you're trying to set the Style
property to something of type Setter
.
<StackPanel.Style>
<Style>
<Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
</Style>
</StackPanel.Style>
精彩评论