0

对于我的 UWP 应用程序,我使用带有ListView的随机访问数据虚拟化。我的问题是,对于这个特定 ListView 的内容,占位符需要是白色的。在 Remarks 下的文档中似乎有资源键ListViewItemPlaceholderBackground,但是我不知道如何覆盖它。

我试图为我的UserControl实现样式资源:

我的用户控件

<UserControl
    x:Class="SimplePdfViewer.SimplePdfViewerControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SimplePdfViewer"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Unloaded="root_Unloaded"
    x:Name="root">

    <Grid>
        <!--ScrollViewer.VerticalScrollBarVisibility="Hidden"-->
        <!--ScrollViewer.ZoomMode="Disabled"-->
        <ListView x:Name="PdfListView" ItemsSource="{x:Bind DocumentDataSource}" ScrollViewer.ZoomMode="Enabled" ScrollViewer.IsScrollInertiaEnabled="True">

            <ListView.ItemTemplate>
                <DataTemplate x:DataType="BitmapImage">
                    <ListViewItem Height="1200">
                        <Image Source="{x:Bind}"/>
                    </ListViewItem>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>

添加样式资源

<UserControl
    x:Class="SimplePdfViewer.SimplePdfViewerControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SimplePdfViewer"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Unloaded="root_Unloaded"
    x:Name="root">
    <UserControl.Resources>
        <Style TargetType="ListViewItem" x:Name="ListViewItemEdit">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <ListViewItemPresenter ContentTransitions="{TemplateBinding ContentTransitions}"
                        PlaceholderBackground="White"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <!--ScrollViewer.VerticalScrollBarVisibility="Hidden"-->
        <!--ScrollViewer.ZoomMode="Disabled"-->
        <ListView x:Name="PdfListView" ItemsSource="{x:Bind DocumentDataSource}" ScrollViewer.ZoomMode="Enabled" ScrollViewer.IsScrollInertiaEnabled="True">

            <ListView.ItemTemplate>
                <DataTemplate x:DataType="BitmapImage">
                    <ListViewItem Height="1200" Style="{StaticResource ListViewItemEdit}">
                        <Image Source="{x:Bind}"/>
                    </ListViewItem>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>

我在网上没有找到任何有用的东西;希望有人可以帮助我。

干杯。

4

1 回答 1

1

而不是在样式中x:Name使用x:Key,然后从 的ItemContainerTemplate属性中引用它ListView

<ListView ... ItemContainerTemplate="{StaticResource ListViewItemEdit}">

但是,如果您这样做,您将在 中只有部分功能ItemContainerTemplate,这不是您想要的。我会从此处复制并粘贴完整Style文档,然后在此处编辑颜色。或者,您可以只提供自定义版本的画笔,而根本不编辑容器。只需删除样式并添加它:

<UserControl.Resources>
    <SolidColorBrush Color="Blue" x:Key="ListViewItemPlaceholderBackgroundThemeBrush" />
</UserControl.Resources>

这应该覆盖该控件的系统默认颜色。

于 2018-08-01T14:18:28.130 回答