简体   繁体   English

弹出窗口中的WPF ListBox在PopupClose上设置为null SelectedItem

[英]WPF ListBox in Popup setting null SelectedItem on PopupClose

I have a WPF Popup, which is structured as below (with some senstitive stuff removed)... 我有一个WPF弹出窗口,其结构如下(删除了一些敏感内容)...

<Popup>
  <Border>
    <StackPanel>

       <ListBox 
          ItemSource="{Binding X}"
          SelectedItem="{Binding Y}"
          IsSynchronizedWithCurrentItem="True"/>

       <Separator/>

       <MenuItem Command="{Binding Path=EditModeCommand}"/>

    </StackPanel>      
  </Border>
</Popup> 

The ListBox works as expected, the list populates from the binding, and the selected item feeds back to the collection correctly. ListBox可以正常工作,列表从绑定中填充,并且所选项目正确地反馈到集合。

However when the MenuItem fires its command, the SelectedItem binding fires as well, setting the SelectedItem to null. 但是,当MenuItem触发其命令时,也会触发SelectedItem绑定,将SelectedItem设置为null。 Is there a way to preserve the SelectedItem when the listbox is not the focus of the click? 当列表框不是单击焦点时,是否可以保留SelectedItem?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM