我有一个固定宽度的StackPanel
。在StackPanel
里面,我有一个GridView
,其中Width
应该被限制在它的父宽度(像宽度=“*”一样)。从父级继承的GridView宽度
我的样品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
宽度设置为固定值时,项目被打包,但我无法在我的项目中使用固定值。
为什么在GridView中使用TextBox?请参阅[WINDOWS 8的GRIDVIEW - 不是为数据输入!](http://netitude.bc3tech.net/2013/04/12/windows-8s-gridviewnot-meant-for-data-entry/) – Xyroid 2013-05-08 11:34:42
TextBoxes在我的例子中只用作示例项目,实际上我只在该GridView中提供数据 – filip 2013-05-08 11:38:17