I’ve added a simple contextmenu to my link template.
<go:LinkPanel go:Part.SelectionElementName="Path"
go:Part.SelectionAdorned="True">
I’ve added a simple contextmenu to my link template.
For the version 1.3 kit we have added a simple app that includes context menus for nodes, for links, and for the background. This app does not demonstrate the behavior that you are talking about.
Here’s the link template from that “BasicApp”:
[code] <go:BooleanBrushConverter x:Key=“theSelectionConverter”
FalseBrush=“Transparent” TrueBrush=“DodgerBlue” />
<DataTemplate x:Key="MyLinkTemplate">
<go:LinkPanel>
<go:Link.Route>
<go:Route RelinkableFrom="True" RelinkableTo="True" />
</go:Link.Route>
<go:LinkShape Stroke="{Binding Path=Part.IsSelected, Converter={StaticResource theSelectionConverter}}"
StrokeThickness="5" />
<go:LinkShape x:Name="Path" Stroke="Black" StrokeThickness="1" />
<Path Fill="Black" go:LinkPanel.ToArrow="Standard" />
<input:ContextMenuService.ContextMenu>
<input:ContextMenu>
<input:MenuItem Header="a link command" Click="LinkMenuClick" />
</input:ContextMenu>
</input:ContextMenuService.ContextMenu>
</go:LinkPanel>
</DataTemplate>[/code]
And the code-behind:
private void LinkMenuClick(object sender, RoutedEventArgs e) {
var elt = sender as FrameworkElement;
if (elt != null && elt.DataContext != null) {
var data = ((PartManager.PartBinding)elt.DataContext).Data as MyLinkData;
MessageBox.Show("Link: " + data.ToString());
}
}
Where can I get that BasicApp? I went to the download area but I only see 1.2.
That’s interesting – so there is a problem with context menus in Silverlight when using the standard selection adornment on links.
The reason is that the standard Silverlight mechanisms for dealing with mouse right button events will result in finding the selection adornment of a selected link, because the selection adornment is in front of the link shape. But there’s no context menu declared for that adornment, so it does nothing.
I have modified the example app not to use a selection adornment but to change the color of the thick link shape that is normally transparent. Now it turns blue when the link is selected.