Note that there are some explanatory texts on larger screens.

plurals
  1. POElementName Binding from MenuItem in ContextMenu
    primarykey
    data
    text
    <p>Has anybody else noticed that Bindings with ElementName do not resolve correctly for <code>MenuItem</code> objects that are contained within <code>ContextMenu</code> objects? Check out this sample:</p> <pre><code>&lt;Window x:Class="EmptyWPF.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" x:Name="window"&gt; &lt;Grid x:Name="grid" Background="Wheat"&gt; &lt;Grid.ContextMenu&gt; &lt;ContextMenu x:Name="menu"&gt; &lt;MenuItem x:Name="menuItem" Header="Window" Tag="{Binding ElementName=window}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Grid" Tag="{Binding ElementName=grid}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Menu" Tag="{Binding ElementName=menu}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Menu Item" Tag="{Binding ElementName=menuItem}" Click="MenuItem_Click"/&gt; &lt;/ContextMenu&gt; &lt;/Grid.ContextMenu&gt; &lt;Button Content="Menu" HorizontalAlignment="Center" VerticalAlignment="Center" Click="MenuItem_Click" Tag="{Binding ElementName=menu}"/&gt; &lt;Menu HorizontalAlignment="Center" VerticalAlignment="Bottom"&gt; &lt;MenuItem x:Name="anotherMenuItem" Header="Window" Tag="{Binding ElementName=window}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Grid" Tag="{Binding ElementName=grid}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Menu" Tag="{Binding ElementName=menu}" Click="MenuItem_Click"/&gt; &lt;MenuItem Header="Menu Item" Tag="{Binding ElementName=anotherMenuItem}" Click="MenuItem_Click"/&gt; &lt;/Menu&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>All of the bindings work great except for the bindings contained within the ContextMenu. They print an error to the Output window during runtime.</p> <p>Any one know of any work arounds? What's going on here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload