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.
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.
Is there a way to define the ContextMenu as a DataTemplate, and set the RadTreeView to use that?
This is what I have, but it doesn't work as I expect (I get the default silverlight right-click menu)
XAML
<DataTemplate x:Key="TreeViewItemTemplate">
<controlsToolkit:ContextMenuService.ContextMenu>
<controlsToolkit:ContextMenu>
<controlsToolkit:MenuItem Header="New Folder"
Click="NewFolderMenu_Click"/>
</controlsToolkit:ContextMenu>
</controlsToolkit:ContextMenuService.ContextMenu>
</DataTemplate>
CS
var t = new RadTreeView();
t.IsLineEnabled = true;
t.IsDragDropEnabled = true;
t.ItemTemplate = (DataTemplate) MailboxView.MailboxResources["TreeViewItemTemplate"];