简体   繁体   中英

WPF ListBox in Popup setting null SelectedItem on PopupClose

I have a WPF Popup, which is structured as below (with some senstitive stuff removed)...

<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.

However when the MenuItem fires its command, the SelectedItem binding fires as well, setting the SelectedItem to null. Is there a way to preserve the SelectedItem when the listbox is not the focus of the click?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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