title: Creating ContextMenu in XAML, and adding it to an Item in Code?
body: <p>I'm using the ContextMenu control from the Silverlight Toolkit, and I'd like to define the contextmenu in xaml, and "add it" to a control that I create in code.</p>
  
  <p>I'm using the Telerik Outlook Radbar, that contains the Telerik RadTreeView. I'm currently creating the RadTreeView in code via a Converter class, but I'd like each treeviewitem to have a right-click menu.</p>
  
  <p>Is there a way to define the ContextMenu as a DataTemplate, and set the RadTreeView to use that?</p>
  
  <p>This is what I have, but it doesn't work as I expect (I get the default silverlight right-click menu)</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;DataTemplate x:Key="TreeViewItemTemplate"&gt;
      &lt;controlsToolkit:ContextMenuService.ContextMenu&gt;
         &lt;controlsToolkit:ContextMenu&gt;
            &lt;controlsToolkit:MenuItem Header="New Folder" 
                                      Click="NewFolderMenu_Click"/&gt;
         &lt;/controlsToolkit:ContextMenu&gt;
      &lt;/controlsToolkit:ContextMenuService.ContextMenu&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p><strong>CS</strong></p>
  
  <pre><code>var t = new RadTreeView();
  
  t.IsLineEnabled = true;
  t.IsDragDropEnabled = true;
  t.ItemTemplate = (DataTemplate) MailboxView.MailboxResources["TreeViewItemTemplate"];
  </code></pre>