在ListView.ItemsPanel中使用StackPanel的对齐问题 [英] Alignment issues using StackPanel in ListView.ItemsPanel

查看:61
本文介绍了在ListView.ItemsPanel中使用StackPanel的对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一组水平移动的团队,而每个团队中的玩家都在下降.为此,我将一个ListView(lvwTeams)绑定到一组Teams.我将lvwTeams.ItemsPanel更改为StackPanel,并将其方向设置为Horizo​​ntal.将ItemTemplate更改为包含另一个ListView(lvwPlayers),该列表绑定到Team的Players集合.

I want to display a collection of Teams going horizontally, with the Players in each Team going down. To achieve this I have a ListView (lvwTeams) bound to a collection of Teams. I change the lvwTeams.ItemsPanel to a StackPanel with its orientation set to Horizontal. The ItemTemplate is changed to contain another ListView (lvwPlayers), which is bound to the Players collection of the Team.

所有方法都可以正常工作,但是ItemTemplate中定义的控件出现在StackPanel的中间.有什么办法可以让lblTeamName位于顶部,而lvwPlayers置于其下方,却可以填充StackPanel给定的其余区域?

All is working, but the controls defined in the ItemTemplate appear in the middle of the StackPanel. Is there any way I can get lblTeamName positioned at the top, with lvwPlayers positioned underneath this, but filling the remaining area given by the StackPanel?

这是XAML:

 <ListView x:Name="lvwTeams" Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Teams}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"></StackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>

    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Label x:Name="lblTeamName" Grid.Row="0" Content="{Binding Name}"/>
                <ListView x:Name="lvwPlayers" Grid.Row="1" ItemsSource="{Binding Players}" >
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Label Content="{Binding FullName}"/>
                        </DataTemplate>
                    </ListView.ItemTemplate>

                </ListView>
            </Grid>

        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

推荐答案

尝试对ListView的内容进行拉伸,如下所示:

Try putting stretch on the content of the ListView, like this:

        <ListView x:Name="lvwTeams" 
              Grid.Row="1" 
              Grid.Column="1" 
              ItemsSource="{Binding Teams}"
              HorizontalContentAlignment="Stretch" 
              VerticalContentAlignment="Stretch">

然后将*放在网格的第二行上,以拉伸第二个ListView.

And put * on the Second Row of the grid, to stretch the second ListView.

<ListView.ItemTemplate>
     <DataTemplate>
         <Grid>
           <Grid.RowDefinitions>
               <RowDefinition Height="Auto"/>
               <RowDefinition Height="*"/>
           </Grid.RowDefinitions>

这篇关于在ListView.ItemsPanel中使用StackPanel的对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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