开发者

Why cant i add Orientation property to the Style Setter in WPF

When i write something like this:

  <Style x:Key="panelS">
            <Setter Property="Orientation" Value="Horizontal" />
            <Setter Property="DockPanel.Dock" 开发者_如何学PythonValue="Top" />
  </Style>

I get the error that says: Cannot resolve the Style Property 'Orientation'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property.

Sure i have a Dock panel with many Stackpanels in it so i want to move Stackpanel's properties to the style. But there is this error and i dont quite understand what it means and what is the workaround(..i'd wanted not to assign Orientation on every Stackpanel).


Your Style isn't associated with the StackPanel type.

Therefore, WPF doesn't know about the Orientation property. (Because that property is defined by StackPanel)

You can explicitly tell WPF which class defines the property by changing it to StackPanel.Orientation.

Alternatively, you can associate the Style with the StackPanel type by adding a TargetType="StackPanel" to the <Style> element.


Try adding a TargetType to the style, so that it knows you are talking about StackPanels. This version should work:

<Style x:Key="panelS" TargetType="StackPanel">
    <Setter Property="Orientation" Value="Horizontal" />
    <Setter Property="DockPanel.Dock" Value="Top" />
</Style>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜