title: WPF popup doesn`t close on click
body: <p><strong>Update:</strong>
  Here is a link for a reproduction
  <a href="https://drive.google.com/file/d/0BzalDCHAtuAPUk5vWF9PVUE2QzQ/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0BzalDCHAtuAPUk5vWF9PVUE2QzQ/view?usp=sharing</a></p>
  
  <p><strong>Back to original question:</strong></p>
  
  <p>I tried to find some answer here but haven`t found any.</p>
  
  <p>I have a collection of items where on click of an item a popup is opened, and when clicked outside of the item the popup is closed. From some reason, when the popup is opened, when I click the same item again the popup is closed and reopened instead of staying closed.
  Here are my pieces of code:</p>
  
  <p><strong>Some clarification:</strong>
  I have two collections. One is sitting inside an ItemsControl and one is sitting inside a ListView. The MouseClickToCommandBehavior below sits on both the ItemsControl and the ListView. I use it to tell the Popup when to open and close. I also need the popup to close when I click outside of the item.
  Currently when I click an item inside the ListView or the ItemsControl (when the popup for that item is already opened) the Popup reopens instead of closing.
  This occurs because of the StaysOpen property set to "false" which is required for the popup to close when I click outside of the item.</p>
  
  <p><strong>Back to original question:</strong></p>
  
  <p>The popup</p>
  
  <pre><code>&lt;Popup IsOpen="{Binding ShowCustomerCardOptionsPopup, UpdateSourceTrigger=PropertyChanged}" StaysOpen="False"
         PlacementTarget="{Binding ElementName=CUstomerCardGrid}"
         Placement="Right"&gt;
  </code></pre>
  
  <p>The behavior to open the popup (which is set on the ListView)</p>
  
  <pre><code>&lt;i:Interaction.Behaviors&gt;
      &lt;behaviors:MouseClickToCommandBehavior Command="{Binding OpenPopupForCustomerCard}" CommandParameter="{Binding ElementName=CustomerCardsListView, Path=SelectedItem}"/&gt;
  &lt;/i:Interaction.Behaviors&gt;
  </code></pre>
  
  <p>The command action</p>
  
  <pre><code>private void OpenPopupForCustomerCardAction(ICustomerModel model)
  {
      model.ShowCustomerCardOptionsPopup = !model.ShowCustomerCardOptionsPopup;
  }
  </code></pre>
  
  <p>And the call stack when clicking on the same item</p>
  
  <pre><code>value: True
  at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  at System.Environment.get_StackTrace()
  at POS.Models.CustomerModel.set_ShowCustomerCardOptionsPopup(Boolean value)
  at POS.ViewModels.CustomerViewModel.OpenPopupForCustomerCardAction(ICustomerModel model)
  at POS.InfraStructure.ActionCommand`1.Execute(Object parameter)
  at POS.Views.Behaviors.MouseClickToCommandBehavior.AssociatedObject_MouseUp(Object sender, MouseButtonEventArgs e)
  
  ====================
  value: False
  at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  at System.Environment.get_StackTrace()
  at POS.Models.CustomerModel.set_ShowCustomerCardOptionsPopup(Boolean value)
  
  ====================
  value: False
  at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  at System.Environment.get_StackTrace()
  at POS.Models.CustomerModel.set_ShowCustomerCardOptionsPopup(Boolean value)
  
  ====================
  value: True
  at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  at System.Environment.get_StackTrace()
  at POS.Models.CustomerModel.set_ShowCustomerCardOptionsPopup(Boolean value)
  at POS.ViewModels.CustomerViewModel.OpenPopupForCustomerCardAction(ICustomerModel model)
  at POS.InfraStructure.ActionCommand`1.Execute(Object parameter)
  at POS.Views.Behaviors.MouseClickToCommandBehavior.AssociatedObject_MouseUp(Object sender, MouseButtonEventArgs e)
  </code></pre>
  
  <p>I would love to know why is the "false" value called twice
  and how can I prevent either the false or second true from occurring (more
  preferbly the false and still have the behavior of StaysOpen="False")</p>
  
  <p>Thanks</p>