title: Binding an enum to MVVM Light RelayCommand<T> CommandParameter
body: <p>I'm trying to bind the command parameter in XAML for a RelayCommand<code>&lt;MessageTokens</code>> as below, where MessageTokens is an enum</p>
  
  <pre><code> public ICommand OpenInvoiceWindowCommand
          {
              get
              {
                  return _openInvoiceWindowCommand ??
                         (_openInvoiceWindowCommand = new RelayCommand&lt;MessageTokens&gt;(OpenInvoiceWindow, prm =&gt; CanExecuteOpenInvoiceWindowCommand));
              }
          }
  </code></pre>
  
  <p>The XAML is:</p>
  
  <pre><code>  &lt;Controls1:RadMenuItem Command="{Binding SupplierInvoiceViewModel.OpenInvoiceWindowCommand}" CommandParameter="{Binding Source={x:Type ShipmentDetails:DebitInvoiceViewModelBase}, Path=MessageTokens.SupplierInvoice}" Header="Register a supplier's invoice"/&gt;
  </code></pre>
  
  <p>Using Telerik's RadGridView the code crashes with</p>
  
  <pre>
     at GalaSoft.MvvmLight.Command.RelayCommand`1.CanExecute(Object parameter)
     at Telerik.Windows.Controls.RadMenuItem.CanExecuteApply() in c:\Builds\WPF_Scrum\HotFix_2010_Q3\Sources\Development\Controls\Navigation\Menu\RadMenuItem.cs:line 2105
     at Telerik.Windows.Controls.RadMenuItem.ChangeCommand(ICommand oldCommand, ICommand newCommand) in c:\Builds\WPF_Scrum\HotFix_2010_Q3\Sources\Development\Controls\Navigation\Menu\RadMenuItem.cs:line 2124
     at Telerik.Windows.Controls.RadMenuItem.OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\Builds\WPF_Scrum\HotFix_2010_Q3\Sources\Development\Controls\Navigation\Menu\RadMenuItem.cs:line 1623
     at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
     at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
     at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
     at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
  </pre>
  
  <p>etc.</p>
  
  <p>If I change the parameter to RelayCommand<code>&lt;string</code>> instead of RelayCommand<code>&lt;MessageTokens</code>> the code runs fine.</p>
  
  <p>I'm loathe to do this since I lose all the benefits of strongly typing my parameters.</p>
  
  <p>I suspect that I am not declaring the enum properly in XAML. I've tried </p>
  
  <pre><code>  CommandParameter = "&lt;fullpath&gt;..MessageTokens.SupplierInvoice&gt;"
  </code></pre>
  
  <p>but that gives an InvalidCastException in MVVMLight.</p>
  
  <p>Does anyone have any suggestions?</p>
  
  <p>Many thanks
  Jeremy</p>
  
  <blockquote>
    <p>Edited with the solution</p>
  </blockquote>
  
  <p>The issue was because I wasn't properly referring to the inner class in the CommandParameter binding with the + sign.</p>
  
  <p>the correct XAML should be:</p>
  
  <pre><code>&lt;Controls1:RadMenuItem Command="{Binding SalesInvoiceViewModel.OpenInvoiceWindowCommand}" CommandParameter="{x:Static local:DebitInvoiceViewModelBase+MessageTokens.SalesInvoice}" Header="Raise a sales invoice"/&gt;
  </code></pre>