title: How to enable or disable menu items based on SelectedItems in ListBox
body: <p>Is there a way to do this when the <code>ContextMenu</code> itself is defined inside the <code>ListBox</code>?</p>
  
  <p>I have my ListBox set up like this:</p>
  
  <pre><code>&lt;ListBox Name="lbxFoundFiles" Margin="10,115,10,5" SelectionMode="Multiple"
              VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
              ItemsSource="{Binding FoundFilesInfo}" ItemTemplate="{DynamicResource FoundFilesListItem}"&gt;
      &lt;ListBox.ContextMenu&gt;
          &lt;ContextMenu&gt;
              &lt;MenuItem Name="cmiCopyClipboard" Header="Copy file to clipboard" Click="cmiCopyClipboard_Click"
                          IsEnabled="{Binding ElementName=lbxFoundFiles, Path=SelectedItems.Count}"/&gt;
          &lt;/ContextMenu&gt;
      &lt;/ListBox.ContextMenu&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>But the error message is clear about this (altough IntelliSense does know what I'm looking for):</p>
  
  <pre><code>System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=lbxFoundFiles'. BindingExpression:Path=SelectedItems; DataItem=null; target element is 'MenuItem' (Name='cmiCopyClipboard'); target property is 'IsEnabled' (type 'Boolean')
  </code></pre>
  
  <p>I've seen examples on how to do this when the ContextMenu is defined outside the ListBox, but I need it to work so I can define a static template for all my listboxes.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have prepared a converter for this, but I've read that my original method should work too.</p>
  
  <pre><code>&lt;MenuItem Name="cmiCopyClipboard" Header="Copy file to clipboard" Click="cmiCopyClipboard_Click"
                              IsEnabled="{Binding ElementName=lbxFoundFiles, Path=SelectedItems, Converter={StaticResource HasItems}}"/&gt;
  </code></pre>
  
  <p>And converter:</p>
  
  <pre><code>public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
      return ((IList&lt;FileInformation&gt;)value).Count &gt; 0;
  }
  </code></pre>