Why can't I add the 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" Value="Top" />
  </Style>

I get an error: Unable to resolve orientation to Orientation style. Verify that the owner type is a Style TargetType type or uses the Class.Property syntax to specify a property.
Of course I have a Dock with a lot of Stackpanels, so I want to move the Stackpanel properties into a style. But there is this error, and I don’t quite understand what it means and what the workaround is (.. I would like not to assign an Orientation for each Stackpanel).

+3
source share
2 answers

Style StackPanel.

WPF Orientation. ( StackPanel)

WPF, , StackPanel.Orientation.

Style StackPanel, TargetType="StackPanel" <Style>.

+6

TargetType , , StackPanels. :

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

Source: https://habr.com/ru/post/1747374/


All Articles