BasedOn property not working with ListView

When I use the following code, it works because I use 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 in a ListView, I get a 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' System.Windows.Controls.ListView 'link not found.

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

+3
source share
3 answers

Try the following:

<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListView}">
+3
source

A ListViewdoes not process the view, it delegates this to the property View, which is usually equal GridView. Try to set the style using the key GridViewas the key.

+2
source

. : app1 lib1 lib2, lib1 listview, lib2 , listview, listview. app1 :

lib2, :  

, : StaticResource 'System.Windows.Controls.ListView' . . , VS2008. VS2010, .

0

Source: https://habr.com/ru/post/1740683/


All Articles