title: ContextMenu Closes Immediately
body: <p><strong>Total Edit:</strong></p>
  
  <p>Now I can reproduce my error and I really don't know why it happens. Any help very much appreciated.</p>
  
  <p>I have the following UI:</p>
  
  <pre><code>&lt;Canvas&gt;
      &lt;Button Content="Remove and Readd Rectangle" Click="Button_Click"/&gt;
      &lt;ItemsControl ItemsSource="{Binding Rectangles}"&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;Canvas/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Rectangle Width="{Binding Width}" Height="{Binding Height}" Stroke="Black" Fill="{Binding Color}" MouseUp="Rectangle_MouseUp" &gt;
                      &lt;Rectangle.Resources&gt;
                          &lt;RaAtt:RaAttached_BindingProxy Data="{Binding}" x:Key="Data"/&gt;
                      &lt;/Rectangle.Resources&gt;
                      &lt;Rectangle.ContextMenu&gt;
                          &lt;ContextMenu IsOpen="{Binding Data.IsOpen, Source={StaticResource Data}}"&gt;
                              &lt;MenuItem Header="Test"/&gt;
                          &lt;/ContextMenu&gt;
                      &lt;/Rectangle.ContextMenu&gt;
                  &lt;/Rectangle&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
          &lt;ItemsControl.ItemContainerStyle&gt;
              &lt;Style&gt;
                  &lt;Setter Property="Canvas.Left" Value="{Binding X}"/&gt;
                  &lt;Setter Property="Canvas.Top" Value="{Binding Y}"/&gt;
              &lt;/Style&gt;
          &lt;/ItemsControl.ItemContainerStyle&gt;
      &lt;/ItemsControl&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>Now I want to open a ContextMenu via a MouseClick on the Rectangle:</p>
  
  <pre><code>private void Rectangle_MouseUp(object sender, MouseButtonEventArgs e)
  {
      ((sender as Rectangle).DataContext as MyRectangle).IsOpen = true;
      e.Handled = true;
  }
  </code></pre>
  
  <p>It works on every single Rectangle.</p>
  
  <p>When I click the Button I remove and immediately readd a Rectangle:</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
  {
      MyRectangle x = Rectangles.FirstOrDefault();
      Rectangles.Remove(x);
      Rectangles.Insert(0, x);
  }
  </code></pre>
  
  <p>If I do this on this removed and readded rectangle the ContextMenu opens and immediately closes again.</p>
  
  <p><strong>Focus log:</strong></p>
  
  <p><em>Start Application:</em></p>
  
  <pre><code>'KeyboardFocus:' TestNamespace.MainWindow
  </code></pre>
  
  <p><em>RightClick:</em></p>
  
  <pre><code>'KeyboardFocus:' System.Windows.Controls.ContextMenu Items.Count:1
  'KeyboardFocus:' TestNamespace.MainWindow
  </code></pre>
  
  <p><em>Click on Button:</em></p>
  
  <pre><code>'KeyboardFocus:' System.Windows.Controls.Button: Remove and Readd Rectangle
  </code></pre>
  
  <p><em>RightClick:</em>    </p>
  
  <pre><code>'KeyboardFocus:' System.Windows.Controls.ContextMenu Items.Count:1
  'KeyboardFocus:' System.Windows.Controls.Button: Remove and Readd Rectangle
  'KeyboardFocus:' System.Windows.Controls.ContextMenu Items.Count:1 //Why does this here happen?
  'KeyboardFocus:' System.Windows.Controls.Button: Remove and Readd Rectangle
  </code></pre>
  
  <p>Does anyone know why?</p>
  
  <p>Thank you so much! </p>