Styling ListView hovered/selected state for Universal Windows Platform

三世轮回 提交于 2019-12-24 16:03:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!