我正在使用 aListView
來顯示專案串列。但是當我使用設定專案的字體ItemContainerStyle
并且現在選擇了一個專案時,ListView
突出顯示(左側的藍線)不再可見。在此螢屏截圖中,這是一個比較。問題出在安裝Microsoft.UI.Xaml
包,因為這里的設計ListView
已經改變。有什么方法可以解決這個問題而不必洗掉ItemContainerStyle
或Microsoft.UI.Xaml
包裝?
主頁.xaml
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<ListView HorizontalAlignment="Left">
<ListViewItem Content="ABCD"/>
<ListViewItem Content="abcd"/>
<ListViewItem Content="1234"/>
</ListView>
<ListView HorizontalAlignment="Right">
<ListViewItem Content="ABCD"/>
<ListViewItem Content="abcd"/>
<ListViewItem Content="1234"/>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="FontSize" Value="16"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Page>
應用程式.xaml
<Application
x:Class="App1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
uj5u.com熱心網友回復:
此行為的原因是,當您為串列視圖設定新ItemContainerStyle
的時,它會覆寫 WinUI 庫中使用的默認項樣式。
對此的解決方案是,您需要根據專案當前使用的樣式為專案指定樣式。ListViewItem
我在 WinUI GitHub 中找到了默認樣式: ListViewItem_themeresources。所以你只需要創建一個基于DefaultListViewItemStyle
.
您將需要像這樣更改一些代碼:
<ListView>
<ListViewItem Content="ABCD"/>
<ListViewItem Content="abcd"/>
<ListViewItem Content="1234" />
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource DefaultListViewItemStyle}">
<Setter Property="FontSize" Value="25"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/508547.html