开发者

wpf, Style, Setters

开发者 https://www.devze.com 2022-12-27 07:34 出处:网络
I\'ve got question about wpf xaml style definitions. When I try to set style in this way: <StackPanel Orientation=\"Vertical\">

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> 
0

精彩评论

暂无评论...
验证码 换一张
取 消