tags:

views:

47

answers:

2

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.

+1  A: 

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.

Timores
Was helpful(and something I can work with) but the solution did not solve the problem :)
bobjink
+1  A: 

Try this one:

<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListView}">
majocha
Good idea and I guess it answers my question! Result was not what I wanted though.
bobjink
Check my answer in http://stackoverflow.com/questions/2593042/datatemplates-while-using-theme-does-not-work-wpf/2619309#2619309
majocha