How to apply WPF ScrollBar style to a particular l

2019-07-04 06:21发布

问题:

Ok, here is my scrollbar style.

<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">       
    <Setter Property="Background" Value="#D5E0FF" />
</Style>

If I apply this, all scrollbars in my application will get affected, undoubtedly.

Now I have 2 listview(s) in my application, I need to apply this style to only a particular listview, while another one remain default scrollbar, any idea?

This is driving me crazy.

Thanks.

回答1:

Add the style as a resource to the ListView itself.

<ListView>
    <ListView.Resources>
        <Style TargetType="ScrollBar">
            ...
        </Style>
    </ListView.Resources>
</ListView>