我的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。如果Orientation设置为vertical
,我希望WrapPanel现在水平填充整个控件,反之亦然。
有没有人知道这样做的好方法?
修改
该属性的类型为System.Windows.Controls.Orientation
,可能的值为:System.Windows.Controls.Orientation.Vertical
和System.Windows.Controls.Orientation.Horizontal
。
答案 0 :(得分:1)
如果您将Background
设置为WrapPanel
,则面板为完整尺寸
我认为您应该使用DockPanel
而不是WrapPanel
使用属性值LastChildFill="True"
。
您的错误来自无效值。为Orientation
属性设置有效的起始值
private Orientation orientation = Orientation.Horizontal;