[英]WPF ListView with GridView not updating SelectionBox after changing SelectedIndex
我有一個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>
我也在網上搜索其他解決方案,但找不到適合我的解決方案。
謝謝@dymanoid
以問題解決的ListViewItem樣式將FocusVisualStyle
設置為{x:Null}
。
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.