3

我对 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>

代码来自这个问题:

水平排列 ListView 项目

4

2 回答 2

2

使用WrapPanel具有固定大小的 a 或您的ListViewItem.

于 2013-06-18T08:16:35.733 回答
1

包裹板呢?

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>
于 2013-06-18T08:17:31.543 回答