2
votes

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?

1
I'm unable to reproduce this. For me, the SelectedItem stays the same when the Command fires and when the Popup closes. Are you able to reproduce your problem in a small test app?Fredrik Hedblad

1 Answers