Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当listview失去焦点时,所选项目为空_C#_Wpf_Mvvm Light - Fatal编程技术网

C# 当listview失去焦点时,所选项目为空

C# 当listview失去焦点时,所选项目为空,c#,wpf,mvvm-light,C#,Wpf,Mvvm Light,我对wpf中的listview有问题。这就是我所拥有的: <ListView Style="{DynamicResource VirtualisedMetroListView}" SelectedItem="{Binding SelectedCode}" ....... > <i:Interaction.Triggers> <i:EventTrigger EventName="Selection

我对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为空,因此我无法删除该项

你知道我如何在点击其他元素(在本例中是功能区)时保持selectedItem吗

提前感谢。

删除此项

 <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="IsSelected" Value="True"></Setter>
 </Trigger>


我不知道所选项目的绑定位置。它绑定到相应的视图模型。这解决了我的问题,但现在我有了另一个问题。因为我的listview有文本框和组合框,所以我希望在单击它们时选择该项目…试试这个