如何在UWP中更改ListViewItem占位符颜色?
对于我的UWP应用程序,我使用的是列表视图。我的问题是,对于这个特定ListView的内容,占位符必须是白色的。在下面的备注中,似乎有资源键ListViewItemPlaceholderBackground,但是我不知道如何覆盖它 我已尝试为我的用户控件实现样式资源: 我的用户控件如何在UWP中更改ListViewItem占位符颜色?,listview,uwp,placeholder,listviewitem,data-virtualization,Listview,Uwp,Placeholder,Listviewitem,Data Virtualization,对于我的UWP应用程序,我使用的是列表视图。我的问题是,对于这个特定ListView的内容,占位符必须是白色的。在下面的备注中,似乎有资源键ListViewItemPlaceholderBackground,但是我不知道如何覆盖它 我已尝试为我的用户控件实现样式资源: 我的用户控件 <UserControl x:Class="SimplePdfViewer.SimplePdfViewerControl" xmlns="http://schemas.microsoft.com
<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>
我没有在网上找到任何有用的东西;希望有人能帮我
干杯。在样式中使用
x:Key
而不是x:Name
,然后从列表视图的ItemContainerTemplate
属性中引用它:
<ListView ... ItemContainerTemplate="{StaticResource ListViewItemEdit}">
这将覆盖此控件的系统默认颜色。我在ListView中使用ItemContainerStyle将占位符涂成白色;如果我使用do I have对ListViewItem执行任何操作,或者只是将其添加到resources部分,那么只要添加它就足够了,资源系统在搜索资源键时就会选择它
<UserControl.Resources>
<SolidColorBrush Color="Blue" x:Key="ListViewItemPlaceholderBackgroundThemeBrush" />
</UserControl.Resources>