Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExampleContextMenu.cs
More file actions
Latest commit
87 lines (76 loc) · 2.65 KB
/
Copy pathExampleContextMenu.cs
File metadata and controls
87 lines (76 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
usingSystem;
usingSystem.Diagnostics;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Input;
usingWholeTomatoSoftware.SourceLinks;
namespaceSourceLinksExamplePlugin
{
internalclassExampleContextMenu:ContextMenu
{
internalclassExampleContextMenuItem:MenuItem,ICommand
{
publicExampleContextMenuItem(MarkerContextctx,stringtext)
{
_ctx=ctx;
// Header text might be dependent upon state in ctx MarkerContext
Header=text;
Command=this;
// Icon = new Image { Source = YourImage };
}
publicboolCanExecute(objectparameter)
{
// CanExecute might be dependent upon state in ctx MarkerContext
returntrue;
}
publicvoidExecute(objectparameter)
{
Debug.WriteLine("ExampleContextMenuItem.Execute called");
// Execute might be dependent upon state in ctx MarkerContext
}
publiceventEventHandlerCanExecuteChanged;
privateMarkerContext_ctx;
}
internalExampleContextMenu(MarkerContextctx)
{
// Wire up theming of ContextMenu and MenuItem via Visual Assist VaWPFTheming.dll
Resources.MergedDictionaries.Add(newResourceDictionary()
{
Source=newUri("pack://application:,,,/VaWPFTheming;component/ThemedControls.xaml",UriKind.Absolute)
});
Style=TryFindResource(typeof(ContextMenu))asStyle;
// if menu is executed using keyboard, use marker's bounding rectangle to position the menu
if(ctx!=null&&(bool)ctx.GetNamedProperty(MarkerContext.NamedProperties.IsMouseEvent)==false)
{
// get the bounding rectangle of the marker, it is returned as double[4] { left, top, right, bottom }
double[]markerBounds=ctx.GetNamedProperty(MarkerContext.NamedProperties.MarkerBoundsScreen)asdouble[];
if(markerBounds!=null&&markerBounds.Length==4)
{
// apply rectangle as a PlacementRectangle
PlacementRectangle=newRect(newPoint(markerBounds[0],markerBounds[1]),newPoint(markerBounds[2],markerBounds[3]));
Placement=System.Windows.Controls.Primitives.PlacementMode.Bottom;
}
}
// add context menu command items
Items.Add(newExampleContextMenuItem(ctx,"Command _1")
{
Style=TryFindResource(typeof(MenuItem))asStyle
});
Items.Add(newExampleContextMenuItem(ctx,"Command _2")
{
Style=TryFindResource(typeof(MenuItem))asStyle
});
Items.Add(newSeparator());
Items.Add(newExampleContextMenuItem(ctx,"Command _3")
{
Style=TryFindResource(typeof(MenuItem))asStyle
});
}
protectedoverridevoidOnOpened(RoutedEventArgse)
{
base.OnOpened(e);
if(Items.Count>0)
((MenuItem)Items[0]).Focus();
}
}
}