问题
I would like to change the default styling of ListView
in a Universal Windows Platform app. The default ListView
item has a light gray color for hover, light blue for clicked, darker blue for selected item.
I tried to search and I have tried almost every piece of code, but without success. This is my xaml for ListView:
<Page.Resources>
<DataTemplate x:Key="MasterListViewItemTemplate" x:DataType="model:Thread">
<Grid Margin="0,11,0,13">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="35"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Ellipse Grid.Column="0" Width="35" Height="35" VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush ImageSource="{x:Bind Photo}"/>
</Ellipse.Fill>
</Ellipse>
<TextBlock Grid.Column="1" Text="{x:Bind Name}"/>
</Grid>
</DataTemplate>
</Page.Resources>
<ListView
x:Name="MasterListView"
ItemContainerTransitions="{x:Null}"
ItemTemplate="{StaticResource MasterListViewItemTemplate}"
IsItemClickEnabled="True"
ItemClick="MasterListView_ItemClick">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
回答1:
All this is defined in the ListViewItem style. You can override it and change the values you need easily. I will not copy-paste the complete style because it's huge and you can find it here.
You can also override just a few colors that bother you. At the same link you'll find that the ListViewItemPresenter
has the properties such as SelectedPressedBackground
set to ThemeResources.
SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
This means that overriding those can be the minimum you need to accomplish what you want (overried SystemControlHighlightListAccentHighBrush and so on), but have in mind that doing that will override those resources for the complete app, which may not be what you expect.
来源:https://stackoverflow.com/questions/33977704/styling-listview-hovered-selected-state-for-universal-windows-platform