我有一个 ListView,它有一个基于网格的数据模板。xml如下:
<ListView ItemsSource="{Binding SomeItemSource}" HorizontalAlignment="Stretch" Height="281">
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Margin="3" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Grid content here -->
<TextBlock Text="SomeTextbox"
Margin="5,5,0,0"/>
<TextBox Grid.Column="1"
Margin="0,5,0,0"
Text="{Binding SomeProperty, Mode=TwoWay}"
HorizontalAlignment="Left"
Width="90"/>
<TextBlock Text="AnotherText"
Grid.Column="0"
Grid.Row="1"
Margin="5,5,0,0"/>
<TextBox Grid.Column="1" Grid.Row="1"
Margin="0,5,0,0"
Text="{Binding AnotherProperty, Mode=TwoWay}"
HorizontalAlignment="Stretch"
Width="300"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我想要的是让网格填充(拉伸)父 ListView 的整个水平宽度,但是它当前包裹到其内容总和的宽度。我怎样才能实现我想要的行为?