基于属性不适用于 ListView

Mad*_*sen 5 c# wpf

当我使用以下代码时,它可以工作,因为我使用的是 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>
Run Code Online (Sandbox Code Playgroud)

但是当我将以下代码用于 ListView 时,我收到警告/异常

<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>
Run Code Online (Sandbox Code Playgroud)

“未找到静态资源引用 'System.Windows.Controls.ListView'。”

为什么以及如何解决?我想要 ListView 的功能。

maj*_*cha 3

试试这个:

<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListView}">
Run Code Online (Sandbox Code Playgroud)