title: WPF submenuitem position
body: <p>I have the following menu, I don't want the submenu items to exceed the application window, I want them to show on the right of the menuitem pressed, not to the left. Any suggestions?</p>
  
  <pre><code>&lt;Menu DockPanel.Dock="Top" x:Name="MainMenu" Height="25"&gt;
      &lt;Menu.Background&gt;
          &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt;
              &lt;GradientStop Color="Black" Offset="0"/&gt;
              &lt;GradientStop Color="#FF4C5568" Offset="1"/&gt;
          &lt;/LinearGradientBrush&gt;
      &lt;/Menu.Background&gt;
      &lt;MenuItem Header="Medio" Foreground="White"  HorizontalContentAlignment="Right" HorizontalAlignment="Right"&gt;
          &lt;MenuItem Header="Abrir archivo" VerticalAlignment="Top" HorizontalContentAlignment="Right" HorizontalAlignment="Left" x:Name="OpenVideoFile" Foreground="Black"/&gt;
          &lt;MenuItem Header="Abrir disco" VerticalAlignment="Top" HorizontalContentAlignment="Right" HorizontalAlignment="Left" x:Name="OpenVideoDisc" Foreground="Black"/&gt;
      &lt;/MenuItem&gt;
      &lt;MenuItem Header="Reproducci?n" SubmenuOpened="MenuItem_SubmenuOpened" IsEnabled="{Binding IsReady}" Foreground="White" HorizontalAlignment="Right"&gt;
          &lt;MenuItem Header="T?tulo" Foreground="Black" x:Name="TitleList" IsEnabled="{Binding IsDisc}" ItemsSource="{Binding TitleList}" ItemTemplate="{DynamicResource trackMenuItemTemplate}"/&gt;
          &lt;MenuItem Header="Cap?tulo" Foreground="Black" x:Name="ChapterList" IsEnabled="{Binding IsDisc}" ItemsSource="{Binding ChapterList}" ItemTemplate="{DynamicResource trackMenuItemTemplate}"/&gt;
          &lt;MenuItem Header="Subt?tulo" Foreground="Black" x:Name="SubtitleList" IsEnabled="{Binding IsDisc}" ItemsSource="{Binding SubtitlesList}" ItemTemplate="{DynamicResource trackMenuItemTemplate}"/&gt;
          &lt;MenuItem Header="Pista V?deo" Foreground="Black" x:Name="VideoTrack" IsEnabled="{Binding IsDisc}" ItemsSource="{Binding VideoTracks}" ItemTemplate="{DynamicResource trackMenuItemTemplate}"/&gt;
          &lt;MenuItem Header="Pista Audio" Foreground="Black" x:Name="AudioTrack" IsEnabled="{Binding IsDisc}" ItemsSource="{Binding AudioTracks}" ItemTemplate="{DynamicResource trackMenuItemTemplate}"/&gt;
      &lt;/MenuItem&gt;
      &lt;MenuItem Style="{StaticResource MenuitemStyle}" Width="452" Height="27"     &gt;
          &lt;MenuItem.Header&gt;
              &lt;Grid Visibility="Visible" MouseLeftButtonDown="WindowMouseLeftButtonDown" Background="Transparent"/&gt;
          &lt;/MenuItem.Header&gt;
      &lt;/MenuItem&gt;
      &lt;MenuItem Width="50" Height="22" Style="{StaticResource MenuitemStyle}" RenderTransformOrigin="1.17,0.409"&gt;
          &lt;MenuItem.Header&gt;
              &lt;Button Width="50" BorderThickness="0" x:Name="Close" HorizontalAlignment="Right" VerticalAlignment="Bottom" Style="{StaticResource CloseStyle}" Height="22" Click="Close_Click" Margin="0,0,-26,0"/&gt;
          &lt;/MenuItem.Header&gt;
      &lt;/MenuItem&gt;
  &lt;/Menu&gt;
  </code></pre>
  
  <p>here you can see the image:</p>
  
  <p><img src="https://i.stack.imgur.com/zj1dl.png" alt="enter image description here"></p>