对于我的 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>
我在网上没有找到任何有用的东西;希望有人可以帮助我。
干杯。