Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BasedOn property not working with ListView

Tags:

c#

wpf

When I use the following code it works because I am using a ListBox

<UserControl.Resources>
    <Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListBox}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Background" Value="Transparent" />
    </Style>
</UserControl.Resources>

But when I use the following code to a ListView I get an warning/exception

<UserControl.Resources>
    <Style BasedOn="{StaticResource {x:Type ListView}}" TargetType="{x:Type ListView}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Background" Value="Transparent" />
    </Style>
</UserControl.Resources>

"StaticResource reference 'System.Windows.Controls.ListView' was not found."

Why and how to solve it? I want the functionality of a ListView.

like image 924
Mads Andersen Avatar asked Apr 11 '10 18:04

Mads Andersen


2 Answers

Try this one:

<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListView}">
like image 57
majocha Avatar answered Sep 22 '22 13:09

majocha


A ListView does not handle presentation, it delegates this to its View property, which is usually a GridView. Try setting the style using the GridView type as key.

like image 21
Timores Avatar answered Sep 24 '22 13:09

Timores