How to disable ListView's Hover and Tile effec

2019-02-22 12:10发布

I want to disable Tile effect that is some kind of pushed effect and hover background color effect of ListView control, how can i do that?

Thanks

2条回答
疯言疯语
2楼-- · 2019-02-22 12:34

After some googling I found that the highlighting happens in the ListViewItemPresenter, which turns out to be pretty hidden. It's located inside the ControlTemplate of an ListViewItem, which is the ItemContainer for the ListView. The simplest way I've found to disable the effect is to simply override this ControlTemplate:

<ListView>
<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <ContentPresenter/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListView.ItemContainerStyle>
<TextBlock Text="List Item" />
...
<TextBlock Text="List Item" />

source: https://blog.jonstodle.com/uwp-listview-without-highlighting-and-stuff/

查看更多
可以哭但决不认输i
3楼-- · 2019-02-22 12:54

Look at this question: Disable cross-slide selection for a listview

You can also make changes to the template to remove any visual states and adornments - go to the designer and right click your ListView/Edit Additional Templates/Edit Generated Item Container (ItemContainerStyle)/Edit a Copy... - that will extract the template you can modify using your preferred method.

查看更多
登录 后发表回答