user3596113
user3596113

Reputation: 878

Change Orientation of a WrapPanel in Wpf (mvvm)

I got a problem with the design of my WPF program. My XAML looks like this:

<StackPanel Orientation="{Binding Orientation}">
   <Border ... /> 
   <Border ... /> 
   <Border ... />
   <Border Margin="2"
           VerticalAlignment="Stretch"
           CornerRadius="3"
           Padding="4">
      <WrapPanel>
         <TextBlock VerticalAlignment="Center"
                    Text="Time Range:"
                    Width="66" />
         <controls:WinFormsWrapper EndDateTime="{Binding EndDateTime,Mode=TwoWay}"
                                   InitialEndDateTime="{Binding InitialEndDateTime}"
                                   InitialStartDateTime="{Binding InitialStartDateTime}"
                                   StartDateTime="{Binding StartDateTime,Mode=TwoWay}"/>
      </WrapPanel>
   </Border>
   <Border ... /> 
</StackPanel>

Inside The WrapPanel you can see there is my WinFormsWrapper. In my Viewmodel i got a property Orientation which will determine how to Orientate the StackPanel. I want the WrapPanel now to fill the whole control horizontally if the Orientation is set to vertical and vice versa.

Does anyone know a good way to do this?

EDIT:

The Type of the property is System.Windows.Controls.Orientation and the possible values are: System.Windows.Controls.Orientation.Vertical and System.Windows.Controls.Orientation.Horizontal.

Upvotes: 0

Views: 896

Answers (1)

JPOne
JPOne

Reputation: 216

If you set a Background to your WrapPanel the panel is full size.
I think that you should use a DockPanel instead of your WrapPanel with the property value LastChildFill="True".

Your error comes from invalid values. Set a valid start value to your Orientation property

private Orientation orientation = Orientation.Horizontal;

Upvotes: 1

Related Questions