1.2: default context menu in Silverlight 4

In GoSilverlight 1.1 for Silverlight 4 it was unnecessarily complicated to provide a default context menu for a Diagram. In version 1.2 you can now set Diagram.ContextMenuEnabled to true and define a context menu on your Diagram:

[code] . . .
xmlns:input=“clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit”
. . .

  <go:Diagram . . .
              ContextMenuEnabled="True">
    <input:ContextMenuService.ContextMenu>
      <input:ContextMenu>
        <input:MenuItem Header="some default command" Click="MenuItem_Click" />
      </input:ContextMenu>
    </input:ContextMenuService.ContextMenu>
  </go:Diagram>[/code]

Note that this property has no effect on context menus defined in your
node or link DataTemplates, which continue to work as you would expect.

The default value for this property is false to allow tools to receive and handle right-mouse clicks.

When this property is true, the Diagram.CurrentTool will not receive right mouse button events…

Silverlight 3 does not support right mouse button events at all.

here is something I wanted to share. if you are using MVVM Light (free MVVM solution) in your node panel, you can add the following to get the context menu items node data result into your diagram view model.

<DataTemplate x:Key="nodeTemplate">
<go:NodePanel x:Name="nodePanel" go:Node.Location="{Binding Data.Location, Mode=TwoWay}" >
<Controls:ContextMenuService.ContextMenu>
<Controls:ContextMenu>
<Controls:MenuItem x:Name="searchConnected" Header="Search Connected..." > <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding ElementName=myDiagram, Path=DataContext.SearchConnectedCommand}" CommandParameter="{Binding Data}" />
</i:EventTrigger>
</i:Interaction.Triggers> </Controls:MenuItem>
</Controls:ContextMenu>
</Controls:ContextMenuService.ContextMenu>
And in your ViewModel:
public RelayCommand<LatNodeModel> SearchConnectedCommand { get; private set; }
in the ctor:
SearchConnectedCommand = new RelayCommand<LatNodeModel>(OnSearchConnected);
and the delegate:
private void OnSearchConnected(LatNodeModel node) { var model = node; }