简体   繁体   中英

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 .

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM