UWP ListView填充和ScrollView高度

时间:2017-05-21 19:46:32

标签: c# xaml listview uwp scrollview

我有一个ListView,我收集了一些类似便条的内容。

我已经设置了所有ListView元素都有padding="0,0,0,-170"所以我可以在另一个上堆叠笔记,只是为了能够看到他们的标题(标题)并且还能完全看到最后一个音符。它工作得很好,但唯一的问题是,当我在另一个上堆叠更多的音符时,我会发现我的音符底部(底部是指低于标题的所有内容)从ListView中丢失。

这个想法只是为了让它可以进一步滚动(比如添加我用padding带来的170px),但我不知道如何更改滚动高度。我愿意接受任何想法,也许有一些解决方法。

以下是代码:

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="Padding" Value="0,0,0,-170"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="MinHeight" Value="20" />
    </Style>
</ListView.ItemContainerStyle>

<ListView.ItemTemplate>
    <DataTemplate x:DataType="data:Note">
        <StackPanel Height="202" Width="200" Margin="10,0,10,0" BorderThickness="2" BorderBrush="#FF320000" RenderTransformOrigin="0.5,0.5">
            <StackPanel.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF935920" Offset="0"/>
                    <GradientStop Color="#FFC59564" Offset="1"/>
                </LinearGradientBrush>
            </StackPanel.Background>
            <TextBlock Name="header" Text="{Binding header}" Margin="5,5,5,5" Height="30" TextWrapping="NoWrap" HorizontalAlignment="Center" FontSize="20" FontWeight="ExtraBold" Foreground="#FFD6B900" RelativePanel.AlignTopWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True"/>
            <TextBlock Name="content" Text="{Binding content}" Margin="5,0,5,5" Height="135" TextWrapping="Wrap" FontSize="16" FontStyle="Italic" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" RelativePanel.Below="header"/>
            <TextBlock Name="date" Text="{Binding date, Converter={StaticResource DateToStringFormatConverter}}" Margin="5,0,5,0" Height="20" TextWrapping="NoWrap" VerticalAlignment="Bottom" Foreground="Black" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignRightWithPanel="True" HorizontalAlignment="Right"/>
        </StackPanel>
    </DataTemplate>
</ListView.ItemTemplate>

以下是它的样子:

Link to screenshot

1 个答案:

答案 0 :(得分:1)

我写完这篇文章后不久便找到了解决方案:)

我唯一要做的就是在ListView上设置一个合适的填充。

因此,如果在 ItemContainerStyle 中我设置了-170px填充,我只需要将<170px添加到 ListView

有趣的是我之前无法得到它。