簡體   English   中英

uwp列表視圖項目永遠不會覆蓋可用的水平空間

[英]uwp list view item never covers available horizontal space

我有一個水平的listview,並且設置了各種拉伸屬性,但是listview項保留在中心,在實際數據模板網格的左右兩側留有一些空間。 我也注意到垂直列表視圖上的相同行為。

在此處輸入圖片說明

正如您在上方圖像中所看到的那樣,該間隙在那里,並且由listviewitem用來顯示突出顯示。 我想消除這一差距。

<ListView Style="{StaticResource PivotListViewStyle}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid  Style="{StaticResource TileGridStyle}" >
                <-- other irrelivant xaml-->
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

樣式

<Style TargetType="ListView" x:Key="StretchListviewStyle">
    <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="VerticalAlignment" Value="Stretch"/>
            </Style>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="ListView" x:Key="PivotListViewStyle" BasedOn="{StaticResource StretchListviewStyle}">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <ItemsStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>        
</Style>

<Style x:Key="TileGridStretchStyle" TargetType="Grid">
    <Setter Property="Height" Value="{StaticResource MainItemHeight}"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="Margin" Value="2"/>
    <Setter Property="Padding" Value="4"/>
    <Setter Property="Background">
        <Setter.Value>
            <SolidColorBrush Color="{ThemeResource SystemAccentColor}"/>
        </Setter.Value>
    </Setter>
</Style>

<x:Double x:Key="MainItemHeight">114</x:Double>

<Style x:Key="TileGridStyle" TargetType="Grid"  BasedOn="{StaticResource TileGridStretchStyle}">
    <Setter Property="Width" Value="{StaticResource MainItemHeight}"/>
</Style>

攝制

重現該問題,您可以看到這個最小的項目: https : //github.com/touseefbsb/ListViewItemSpacingBug

這是因為ListViewItem的默認Padding12,0,12,0

用另一個值覆蓋填充:

    <Style TargetType="ListView" x:Key="StretchListviewStyle">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="VerticalContentAlignment" Value="Stretch" />
                    <Setter Property="HorizontalAlignment" Value="Stretch" />
                    <Setter Property="VerticalAlignment" Value="Stretch" />
                    <Setter Property="Padding" Value="1"/>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

這就是您得到的:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM