A simple mouse click on a selectable Part will result in that part becoming selected. This is the behavior of the ClickSelectingTool.
If you want to perform some custom action when the user double-clicks on a part, you can define an event handler for the part:<DataTemplate x:Key="NodeTemplate4"> <Border . . . MouseLeftButtonDown="Node_MouseLeftButtonDown"> . . . </Border> </DataTemplate>
private void Node_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (DiagramPanel.IsDoubleClick(e)) { Node node = Part.FindAncestor<Node>(sender as UIElement); if (node != null && node.Data != null) { e.Handled = true; MessageBox.Show("double clicked on " + node.Data.ToString()); } } }
You can implement context menus for nodes easily enough by just defining them in your node template:
<DataTemplate x:Key="NodeTemplate3"> <Border . . .> <ContextMenuService.ContextMenu> <ContextMenu> <MenuItem Header="some node command" Click="MenuItem_Click" /> </ContextMenu> </ContextMenuService.ContextMenu> </Border> </DataTemplate>
<span style=“font-size: 11pt; line-height: 115%; font-family: “Calibri”,“sans-serif”;”>private void MenuItem_Click(object sender, RoutedEventArgs e) {
var partdata = ((FrameworkElement)sender).DataContext as PartManager.PartBinding;
if (partdata == null || partdata.Data == null) {
MessageBox.Show("Clicked on nothing");
} else {
MessageBox.Show("Clicked on data: " + partdata.Data.ToString());
}
}
You can also get the “partdata.Node” if you want access to the Node rather than the data to which the node is bound.
Note that Silverlight 3 does not support
receiving right mouse click events, so you cannot easily implement normal
context menus in Silverlight 3. This will not be a restriction in Silverlight 4.