【问题标题】:WPF Listview Item alignmentWPF Listview 项目对齐
【发布时间】:2013-06-14 08:37:39
【问题描述】:

我对 WPF 相当陌生。

我想知道如何并排对齐项目,但仍然是水平的。

所以让我们坐下这是我现在的物品:

( 0 ) ( 0 ) ( 0 ) ( 0 ) ( 0 ) 

但如果没有更多空间,它只会显示一个滚动条,而不是像这样继续下一行:

( 0 ) ( 0 ) ( 0 )
( 0 ) ( 0 )

这是我的 XAML:

<ListView x:Name="listViewResourceHours" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0" SelectionMode="Single" Height="100" Width="500" >
    <ListView.GroupStyle>
        <GroupStyle>
            <GroupStyle.Panel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </GroupStyle.Panel>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold" Text="{Binding Name, StringFormat={}{0}:}" />
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="GroupItem">
                                <StackPanel Orientation="Horizontal">
                                    <ContentPresenter Margin="0,0,0,0" VerticalAlignment="Center" />
                                    <ItemsPresenter Margin="0,0,0,0" VerticalAlignment="Center"/>
                                </StackPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </ListView.GroupStyle>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" >
                <Label VerticalAlignment="Center"  Margin="0" Content="{Binding Hours}" />
                <Label Name="lblWorkingHours" VerticalAlignment="Center"  Margin="0,0,0,0" Content="{Binding WorkingHoursType, Converter={StaticResource ResourceKey=hoursTypeConverter}}" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>

</ListView>

代码来自这个问题:

Arranging ListView items Horizontally

【问题讨论】:

    标签: wpf listview


    【解决方案1】:

    使用固定大小的WrapPanelListViewItem 的大小。

    【讨论】:

    • 似乎不起作用:(
    • 当我将方向更改为垂直时它仍然不起作用
    • 它不会进入下一行
    • 尝试将WrapPanel 放入&lt;ItemsPanelTemplate&gt;
    • 仍然不起作用,当我选择一个项目时,我可以看到项目的高度填满了整个东西,而不是仅仅创建一个小盒子..
    【解决方案2】:

    包装板怎么样?

    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 2013-04-29
      • 1970-01-01
      • 2015-07-10
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多