在ListView的ItemTemplate填充制作一个网格 [英] Making a grid in a ListView ItemTemplate fill

查看:483
本文介绍了在ListView的ItemTemplate填充制作一个网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有基于网格数据模板一个ListView。 XAML中如下:

I have a ListView which has a data template based on a grid. The xaml is as follows:

        <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的整个水平宽度,但它目前换到其内容之和的宽度。我怎样才能达到我想要的行为?

What I want, is for the grid to fill (stretch over) the entire horizontal width of the parent ListView, however it currently wraps to the width of the sum of its contents. How can I achieve the behavior I want?

推荐答案

您需要设置 ListViewItem.Horizo​​ntalContentAlignment 。尝试添加该到你的的ListView 定义:

You need to set ListViewItem.HorizontalContentAlignment to Stretch. Try adding this into your ListView definition:

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListView.ItemContainerStyle>

这篇关于在ListView的ItemTemplate填充制作一个网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆