tags:

views:

94

answers:

1

Hello,

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:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
                </StackPanel.Style>

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?

+2  A: 

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