【问题标题】:WPF ListView with GridView not updating SelectionBox after changing SelectedIndex更改 SelectedIndex 后,带有 GridView 的 WPF ListView 不更新 SelectionBox
【发布时间】:2018-12-19 05:40:59
【问题描述】:

问题

我有一个 WPF ListView 和一个 GridView 作为 ListView.View 以便在我的 ListView 中有列。在我的代码中,我正在更改 SelectedIndex 属性(绑定到我的 ViewModel 中的一个 int)以更改选择索引。但是这样做会导致先前选择的项目周围出现一个轮廓框(见图)。由于视觉风格,我想删除此轮廓或将其移动到新的选定项目。

我已经尝试过的

我已经尝试过更改 ListViewItem 的 ControlTemplate(代码如下)

<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border Background="{TemplateBinding Background}">
    <GridViewRowPresenter Margin="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
    <Border.InputBindings>
        <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ...}"/>
    </Border.InputBindings>
</Border>
<ControlTemplate.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" Value="#D9EBF9"/>
    </Trigger>
    <Trigger Property="IsMouseOver" Value="False">
        <Setter Property="Background" Value="Transparent"/>
    </Trigger>
    <Trigger Property="IsSelected" Value="True">
        <Setter Property="Background" Value="#CCE8FF"/>
    </Trigger>
</ControlTemplate.Triggers>

我也在网上搜索了其他解决方案,但找不到适合我的解决方案。

【问题讨论】:

  • 可能是this helps
  • @dymanoid 谢谢,这就是解决方案。

标签: c# wpf xaml mvvm


【解决方案1】:

回答

感谢@dymanoid

FocusVisualStyle 设置为{x:Null} 以解决问题的ListViewItem 的样式。

<Setter Property="FocusVisualStyle" Value="{x:Null}"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-09
    • 2014-01-26
    • 2023-04-03
    • 2012-06-12
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多