-1

I have a project with a Templated Silverlight Control. When I add the DLL from the Project (with Templated Control) in my MainPage and want to open the Context Menu with a right click, I get this error:

MainPage.xaml

<MyControls:Draw x:Name="ctrDraw"></MyControls:Draw>

Draw.cs (Templated Silverlight Control)

_contextMenu.IsOpen = true; --> Error

ErrorMessage

errMsg  "Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: Das Festlegen von Eigenschaft 'System.Windows.FrameworkElement.Style' hat eine Ausnahme ausgelöst."
fellowes22
  • 11
  • 2

2 Answers2

1

Init:

 private ContextMenu _contextMenu;
 private MenuItem _contextMenuItem;

Event:

private void map_MouseRightButtonUp(object sender, GraphicMouseButtonEventArgs e)
{
_contextMenu = new ContextMenu();

_contextMenuItem = new MenuItem();
_contextMenuItem.Header = "Edit";
_contextMenu.Items.Add(_contextMenuItem);
_contextMenuItem.Click += new RoutedEventHandler(menuItem_Click);

.....

fellowes22
  • 11
  • 2
0

I don't remember exactly but you can find "ContextMenuService" class and try set like:

ContextMenuService.SetContextMenu(ctrDraw, _contextMenu)
MasterLuV
  • 396
  • 1
  • 17
  • The method IsOpen works if I create a ContextMenu directly in the Main Page file. When I add a DLL(my own Control) to my project and this includes a context menu it crashes. – fellowes22 Apr 24 '15 at 08:18