代码是我的ListView,有时,当我用鼠标左键单击ListViewItem时,仍然选择了先前选择的ListViewItem。这种情况是随机的。有人可以帮忙吗?
我的ListView:
<ListView ItemsSource="{Binding TestsList}"
x:Name="TestsListView"
Style="{StaticResource ListViewStyle}"
ItemContainerStyle="{StaticResource ListViewItemStyle}" />
ListViewStyle:
<Style x:Key="ListViewStyle" TargetType="ListView">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
<Setter Property="SelectionMode" Value="Extended"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
ListViewItemStyle:
<Style x:Key="ListViewItemStyle" TargetType="ListViewItem">
<Setter Property="ins:MouseDoubleClick.Command" Value="{Binding Path=DataContext.OpenCommand,ElementName=TestsListView}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property = "Template">
<Setter.Value>
<ControlTemplate>
<Border x:Name= "ItemBorder" Margin="0,0,0,5" BorderThickness="0" Height="92">
<Border.Background>
<ImageBrush ImageSource="../Images/Item.png"/>
</Border.Background>
<Grid Margin="0,0,0,5" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="NameTextBlock" Grid.Column="1" TextTrimming="CharacterEllipsis" Text="{Binding Name}" FontWeight="Bold" Padding="0,5,10,2"/>
<Image Source="{Binding Icon}" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Top" Width="30" Height="30" Margin="10,2,10,2"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Margin="0,0,10,2">
<Image Source="../Images/Prompt.png" Width="15" Height="15" Margin="0,0,5,0" />
<Image Source="../Images/Warning.png" Width="15" Height="15" Margin="0,0,5,0" />
<TextBlock TextTrimming="CharacterEllipsis" Margin="0,0,20,0">
<Run Text="{Binding DataContext.VersionText,ElementName=TestsListView}" FontWeight="Bold"/>
<Run Text="{Binding Version}"/>
</TextBlock>
<TextBlock TextTrimming="CharacterEllipsis" Margin="0,0,10,0" TextWrapping="NoWrap">
<Run Text="{Binding DataContext.AuthorsText,ElementName=TestsListView}" FontWeight="Bold" />
<Run Text="{Binding Authors}"/>
</TextBlock>
</StackPanel>
<TextBlock Grid.Row="2" Grid.Column="1" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Text="{Binding Description}" Padding="0,0,10,5"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ListViewItem.IsSelected" Value="True">
<Setter TargetName="ItemBorder" Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../Images/Selected.png"/>
</Setter.Value>
</Setter>
</Trigger>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="False">
<Setter TargetName="NameTextBlock" Property="Foreground" Value="#0261A5"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>