我有StackPanel一个固定宽度的。在里面StackPanel我有一个GridView,它Width应该限制在它的父宽度(smth like Width="*")。
我的示例 XAML:
<StackPanel Orientation="Horizontal" Width="300" Height="300">
<TextBox Width="50" Margin="0" Height="50" Background="Blue"></TextBox>
<GridView >
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" FlowDirection="LeftToRight" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Items>
<TextBox Width="50" Margin="0" Height="50" Background="Green"></TextBox>
<TextBox Width="50" Margin="0" Height="50" Background="Green"></TextBox>
<TextBox Width="50" Margin="0" Height="50" Background="Green"></TextBox>
<TextBox Width="50" Margin="0" Height="50" Background="Green"></TextBox>
<TextBox Width="50" Margin="0" Height="50" Background="Green"></TextBox>
</GridView.Items>
</GridView>
</StackPanel>
在此示例中,GridView宽度比父项宽,因此它的一些项目没有显示(未包装)。当我将GridView宽度设置为固定值时,项目被包装,但我不能在我的项目中使用固定值。