我在wpf中遇到listview问题。这就是我所拥有的:
<ListView Style="{DynamicResource VirtualisedMetroListView}" SelectedItem="{Binding SelectedCode}" ....... >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<toolkit:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"></toolkit:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
</ListView.Resources>
<ListView.CacheMode>
<BitmapCache/>
</ListView.CacheMode>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
我还有一个带有几个按钮的功能区,例如:
<fluent:RibbonTabItem Header="Try me" Visibility="Visible" Name="cxtTab" >
<fluent:RibbonGroupBox Header="general">
<Button ContentTemplate="{StaticResource addNewTemplate}"/>
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
现在,我正在使用MVVM Light,并且我将Listview SelectedItem绑定,但是当我单击功能区中的按钮时,selectedITem为null,因此我无法删除该项目。
任何想法,即使我点击其他元素(在这种情况下是功能区),我怎么能保留selectedItem?
提前致谢。
答案 0 :(得分:2)
删除此
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>