开发者

Make a grid's width in ListView.ItemTemplate the same width as the ListViewItem

开发者 https://www.devze.com 2023-03-15 12:52 出处:网络
What I\'m trying to do is to make a Grid inside of the ItemTemplate expand to the width of the ListViewItem and not to just the space it needs. This is how I DON\'T want it to look like:

What I'm trying to do is to make a Grid inside of the ItemTemplate expand to the width of the ListViewItem and not to just the space it needs. This is how I DON'T want it to look like:

Make a grid's width in ListView.ItemTemplate the same width as the ListViewItem

Basically I want the red grid to be the width of the blue rectangle (which is the selected item). This is my XAML:

<ListView ItemsSource="{Binding}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid Background="Red">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" T开发者_开发百科ext="{Binding FirstName}" />
                <TextBlock Grid.Column="1" Text="{Binding LastName}" />
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Thanks in advance!


Do the following:

<ListView ItemsSource="{Binding}">
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
  </ListView.ItemContainerStyle>

  ..
0

精彩评论

暂无评论...
验证码 换一张
取 消