[英]Selected item is null when listview looses focus
我在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?
提前致謝。
刪除這個
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.