title: MenuFlyout fails
body: <p>I'm having some issues with the MenuFlyouts when showing triggered by a RightTapped event on some MapItems and ListViewItems also, so I supposed that it happens with other controls also. </p>
  
  <p>So, when I open the first MenuFlyout, it works ok. The I choose another MapItem and open its MenuFlyout then again it works ok. BUT, if I open a MenuFlyout while I haven't closed the previous, it opens, but the new MenuFlyout background changes to black and the MenuFlyoutItems that contains (Edit, View, ...) they don't respond to the mouse click, nor taps, ... If I try to open another MenuFlyout, both after closed the previous or without closing, it works ok again. </p>
  
  <p>Then, I have debugged to follow whats happening behind the curtains and I've found that when everything is going ok, the event triggered are in order the next(open process):</p>
  
  <ul>
  <li>Opening</li>
  <li>Closing </li>
  <li>Closed</li>
  <li>Opening</li>
  <li>Opened</li>
  </ul>
  
  <p>Closing process (ok):</p>
  
  <ul>
  <li>Closing </li>
  <li>Closed</li>
  </ul>
  
  <p>Opening failed process:</p>
  
  <ul>
  <li>Closing</li>
  <li>Closing</li>
  <li>Closed</li>
  <li>Opening</li>
  <li>Opened</li>
  </ul>
  
  <p>Look that some events are triggered twice and when opening ok, the first three events are a little bit strange (starts opening, the closes to open it again).</p>
  
  <p>There's no error nor exception message on output window.</p>
  
  <p>Why it is happening? How can I fix it?</p>
  
  <p>Maybe, there's some problem when tries to show a second MenyFlyout and it is not possible? In that case, how can I close the previous one before showing the next one?</p>
  
  <p>Below goes all the code that I think it'll be useful.</p>
  
  <p>Thanks</p>
  
  <p>My MenuFlyout is an ContextFlyout. Here's the XAML code:</p>
  
  <pre><code> &lt;Maps:MapItemsControl x:Name="mapSpotsItems"&gt;
  &lt;Maps:MapItemsControl.ItemTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;StackPanel x:Name="spotPin" Visibility="{Binding isVisible}" Maps:MapControl.NormalizedAnchorPoint="{Binding NormalizedAnchorPoint}"
                      Maps:MapControl.Location="{Binding geopoint}" Tag="{Binding ID}" ToolTipService.ToolTip="{Binding AdvancedDescription}" 
                      RenderTransformOrigin="0.5,1" 
  
                      Tapped="spotPin_Tapped" DoubleTapped="spotPin_DoubleTapped" RightTapped="spotPin_RightTapped"
                      PointerEntered="spotPin_PointerEntered" PointerExited="spotPin_PointerExited"
                      &gt;
  
              &lt;StackPanel.ContextFlyout&gt;
                  &lt;MenuFlyout Closing="MenuFlyout_Closing" Closed="MenuFlyout_Closed" Opened="MenuFlyout_Opened" Opening="MenuFlyout_Opening"&gt;
  
                      &lt;MenuFlyout.MenuFlyoutPresenterStyle&gt;
                          &lt;Style TargetType="MenuFlyoutPresenter"&gt;                
                              &lt;Setter Property="Background" Value="{ThemeResource AcrylicDarkGrey50Background}"/&gt;
                              &lt;Setter Property="BorderBrush" Value="{ThemeResource DarkGrey10ThemeColor}"/&gt;
                          &lt;/Style&gt;
                      &lt;/MenuFlyout.MenuFlyoutPresenterStyle&gt;
  
                      &lt;MenuFlyoutItem Text="Open in Planner" Tag="{Binding ID}" Tapped="spotOpenInPlannerFlyoutItem_Tapped"&gt;
  
                      &lt;/MenuFlyoutItem&gt;
  
                      &lt;MenuFlyoutSeparator  /&gt;
  
                      &lt;MenuFlyoutItem Text="View" Tag="{Binding ID}" Tapped="spotViewFlyoutItem_Tapped"&gt;            
                      &lt;/MenuFlyoutItem&gt;
                      &lt;MenuFlyoutItem Text="Edit" Tag="{Binding ID}" Tapped="spotEditFlyoutItem_Tapped"&gt;
                      &lt;/MenuFlyoutItem&gt;
  
                      &lt;MenuFlyoutSeparator Visibility="{Binding Exportable}"/&gt;
  
                      &lt;MenuFlyoutItem Text="Move" Tag="{Binding ID}" Tapped="spotMoveFlyoutItem_Tapped"&gt;
                      &lt;/MenuFlyoutItem&gt;
  
                      &lt;MenuFlyoutSeparator/&gt;
  
                      &lt;MenuFlyoutItem Text="Export" Tag="{Binding ID}" Visibility="{Binding Exportable}" Tapped="spotExportFlyoutItem_Tapped"&gt;
                      &lt;/MenuFlyoutItem&gt;
  
                      &lt;MenuFlyoutSeparator  Visibility="{Binding Exportable}" /&gt;
  
                      &lt;MenuFlyoutItem Text="Delete" Tag="{Binding ID}" Tapped="spotDeleteFlyoutItem_Tapped"&gt;
                      &lt;/MenuFlyoutItem&gt;
  
                  &lt;/MenuFlyout&gt;
              &lt;/StackPanel.ContextFlyout&gt;
  
  
              &lt;StackPanel Orientation="Horizontal" Background="{StaticResource SpotBackgroundColor}" Tag="{Binding ID}"&gt;
                  &lt;Grid&gt;
                      &lt;Rectangle Width="22" Height="22"  Opacity="0.5"/&gt;
                      &lt;Image Source="{Binding MainTag}" Height="20" Width="20" HorizontalAlignment="Center" VerticalAlignment="Center"/&gt;
                  &lt;/Grid&gt;
  
                  &lt;Grid  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                      &lt;TextBlock Text="{Binding Title}" Margin="5,0" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                 Width="50" 
                                 MaxLines="2" TextWrapping="WrapWholeWords" TextTrimming="CharacterEllipsis" LineHeight="11"
                                 Style="{StaticResource BaseTextBlockStyle}" 
                                 FontSize="11" FontWeight="Normal" Foreground="{ThemeResource SpotForegroundColor}" /&gt;
                  &lt;/Grid&gt;
              &lt;/StackPanel&gt;
  
              &lt;Canvas HorizontalAlignment="Center"&gt;
                  &lt;Polygon Fill="{StaticResource SpotBackgroundColor}" Points="-5,0, 0,10, 5,0, -5,0" /&gt;
              &lt;/Canvas&gt;
  
  
          &lt;/StackPanel&gt;
  
      &lt;/DataTemplate&gt;
  &lt;/Maps:MapItemsControl.ItemTemplate&gt;
  
  &lt;/Maps:MapItemsControl&gt;
  </code></pre>
  
  <p>And the C# that opens the MenuFlyout:</p>
  
  <pre><code>private async void spotPin_RightTapped(object sender, RightTappedRoutedEventArgs e)
  {
      onSpotPin = true;
  
      StackPanel sp = sender as StackPanel;
      sp.ContextFlyout.ShowAt((FrameworkElement)sender);
  
      await Task.Delay(globalVars.SINGLE_TAP_MIN_TIME * 2);
      onSpotPin = false;
  
  }
  </code></pre>
  
  <p>Here the events of the MenuFlyouts (why Opening, Opened and Closed parameter types are object and Closing on the other hand, has it's own's?): </p>
  
  <pre><code>private void MenuFlyout_Opening(object sender, object e)
  {
  
  }
  
  private void MenuFlyout_Opened(object sender, object e)
  {
  
  }
  
  private void MenuFlyout_Closed(object sender, object e)
  {
  
  }
  
  private void MenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs args)
  {
  
  }
  </code></pre>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>After trying different ways, finally I have achieved what was my goal: I've created the MenuFlyout and all the items containing by code. </p>
  
  <p>Despite the result, on the way of trying, I've realized that adding or showing the MenuFlyout by code has it's own problems also. </p>
  
  <p>It's curious that when showing the MenuFlyout created by code and attaching to a control, when using this line of code:</p>
  
  <pre><code>f.ShowAt(sender as FrameworkElement);
  </code></pre>
  
  <p>It works ok and fulfills my needs, but if use the same command but with the second parameter, it fails as explained before:</p>
  
  <pre><code>f.ShowAt(sender as FrameworkElement, e.GetPosition(sender as FrameworkElement));
  </code></pre>
  
  <p>Any idea, why?</p>
  
  <p><strong>2nd UPDATE AND SOLUTION</strong></p>
  
  <p>When working with XAML (MenuFlyout defined in XAML), Click event should be chosen instead of Tap event.</p>
  
  <p>When MenuFlyout created in code, Tap event works fine.</p>