[英]Change Orientation of a WrapPanel in Wpf (mvvm)
我的WPF程序设计遇到问题。 我的XAML如下所示:
<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>
在WrapPanel内部,您可以看到我的WinFormsWrapper。 在我的Viewmodel中,我获得了一个Orientation
属性,它将确定如何定向StackPanel。 如果方向设置为vertical
,我现在希望WrapPanel水平填充整个控件,反之亦然。
有人知道这样做的好方法吗?
编辑:
该属性的类型为System.Windows.Controls.Orientation
,可能的值为: System.Windows.Controls.Orientation.Vertical
和System.Windows.Controls.Orientation.Horizontal
。
如果将WrapPanel
设置为Background
,则面板为全尺寸。
我认为您应该使用DockPanel
而不是具有属性值LastChildFill="True"
WrapPanel
。
您的错误来自无效值。 为Orientation
属性设置一个有效的起始值
private Orientation orientation = Orientation.Horizontal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.