今天我开始自学如何创建一个 wpf 应用程序(最后)
所以我开始习惯它,但我在设置列表视图的样式时遇到了一些障碍。
在这张顶部图片中,您可以看到它完美地工作(选择周围没有边框)
但是在第二张图片中,您可以看到选择周围有一个小边框。似乎只有当我使用键盘转到列表中的下一个项目时才会发生这种情况。
我在样式中是否缺少一些东西,所以我可以摆脱这个边框?
代码:(记住我今天才开始学习,所以可能很乱)
列表视图样式
<Style TargetType="{x:Type ListView}">
<Setter Property="BorderThickness" Value="0" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderThickness" Value="0" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="#4b0037" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border
BorderBrush="Transparent"
BorderThickness="0"
Background="{TemplateBinding Background}">
<GridViewRowPresenter HorizontalAlignment="Stretch" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Width="Auto" Margin="0" Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="images/selection.png"/>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="images/selection.png"/>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="#FFFFFF" />
</Trigger>
</Style.Triggers>
</Style>
列表视图 XAML
<ListView Background="transparent" Margin="10 10 10 10" x:Name="Mylist" HorizontalAlignment="Stretch" VerticalContentAlignment="center" VerticalAlignment="Stretch" BorderBrush="Transparent">
<ListView.View>
<GridView>
<GridViewColumn Header="img" Width="150" DisplayMemberBinding="{Binding img}" />
<GridViewColumn Header="name" Width="150" DisplayMemberBinding="{Binding name}" />
<GridViewColumn Header="path" Width="150" DisplayMemberBinding="{Binding path}" />
</GridView>
</ListView.View>
</ListView>