1

我对 wpf xaml 样式定义有疑问。当我尝试以这种方式设置样式时:

<StackPanel Orientation="Vertical">
      <StackPanel.Style>
          <Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
      </StackPanel.Style>
</StackPanel>

引发异常消息 - 'System.Windows.Setter' is not a valid value for property 'Style'

当我使用这个定义时:

<Style x:Key="itemBehaviour" > 
    <Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
</Style>
<StackPanel Orientation="Vertical" Style="{StaticResource itemBehaviour}">

一切正常。

那么区别是什么呢?

4

1 回答 1

4

StackPanel.Style是 type 的属性Style,所以不包装Setterin<Style></Style>你试图将Style属性设置为 type 的东西Setter

<StackPanel.Style>
    <Style>
        <Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
    </Style>
</StackPanel.Style> 
于 2010-04-16T13:06:02.813 回答