FrameworkContentElement.ContextMenuClosing Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs just before any context menu on the element is closed.
public:
event System::Windows::Controls::ContextMenuEventHandler ^ ContextMenuClosing;
public event System.Windows.Controls.ContextMenuEventHandler ContextMenuClosing;
member this.ContextMenuClosing : System.Windows.Controls.ContextMenuEventHandler
Public Custom Event ContextMenuClosing As ContextMenuEventHandler
Event Type
Examples
The following example implements a handler that changes the cursor over a named region DisplayArea
(not shown). The comment hints at a UIElement usage, but in fact this sample would be identical if DisplayArea
were a FrameworkContentElement.
private void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox source = e.Source as ComboBox;
if (source != null)
{
ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;
// Changing the cursor of the Border control
// by setting the Cursor property
switch (selectedCursor.Content.ToString())
{
case "AppStarting":
DisplayArea.Cursor = Cursors.AppStarting;
break;
case "ArrowCD":
DisplayArea.Cursor = Cursors.ArrowCD;
break;
case "Arrow":
DisplayArea.Cursor = Cursors.Arrow;
break;
case "Cross":
DisplayArea.Cursor = Cursors.Cross;
break;
case "HandCursor":
DisplayArea.Cursor = Cursors.Hand;
break;
case "Help":
DisplayArea.Cursor = Cursors.Help;
break;
case "IBeam":
DisplayArea.Cursor = Cursors.IBeam;
break;
case "No":
DisplayArea.Cursor = Cursors.No;
break;
case "None":
DisplayArea.Cursor = Cursors.None;
break;
case "Pen":
DisplayArea.Cursor = Cursors.Pen;
break;
case "ScrollSE":
DisplayArea.Cursor = Cursors.ScrollSE;
break;
case "ScrollWE":
DisplayArea.Cursor = Cursors.ScrollWE;
break;
case "SizeAll":
DisplayArea.Cursor = Cursors.SizeAll;
break;
case "SizeNESW":
DisplayArea.Cursor = Cursors.SizeNESW;
break;
case "SizeNS":
DisplayArea.Cursor = Cursors.SizeNS;
break;
case "SizeNWSE":
DisplayArea.Cursor = Cursors.SizeNWSE;
break;
case "SizeWE":
DisplayArea.Cursor = Cursors.SizeWE;
break;
case "UpArrow":
DisplayArea.Cursor = Cursors.UpArrow;
break;
case "WaitCursor":
DisplayArea.Cursor = Cursors.Wait;
break;
case "Custom":
DisplayArea.Cursor = CustomCursor;
break;
default:
break;
}
// If the cursor scope is set to the entire application
// Use OverrideCursor to force the cursor for all elements
if (!cursorScopeElementOnly)
{
Mouse.OverrideCursor = DisplayArea.Cursor;
}
}
}
' When the Radiobox changes, a new cursor type is set
Private Sub CursorTypeChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
Dim item As String = CType(e.Source, ComboBox).SelectedItem.Content.ToString()
Select Case item
Case "AppStarting"
DisplayArea.Cursor = Cursors.AppStarting
Case "ArrowCD"
DisplayArea.Cursor = Cursors.ArrowCD
Case "Arrow"
DisplayArea.Cursor = Cursors.Arrow
Case "Cross"
DisplayArea.Cursor = Cursors.Cross
Case "HandCursor"
DisplayArea.Cursor = Cursors.Hand
Case "Help"
DisplayArea.Cursor = Cursors.Help
Case "IBeam"
DisplayArea.Cursor = Cursors.IBeam
Case "No"
DisplayArea.Cursor = Cursors.No
Case "None"
DisplayArea.Cursor = Cursors.None
Case "Pen"
DisplayArea.Cursor = Cursors.Pen
Case "ScrollSE"
DisplayArea.Cursor = Cursors.ScrollSE
Case "ScrollWE"
DisplayArea.Cursor = Cursors.ScrollWE
Case "SizeAll"
DisplayArea.Cursor = Cursors.SizeAll
Case "SizeNESW"
DisplayArea.Cursor = Cursors.SizeNESW
Case "SizeNS"
DisplayArea.Cursor = Cursors.SizeNS
Case "SizeNWSE"
DisplayArea.Cursor = Cursors.SizeNWSE
Case "SizeWE"
DisplayArea.Cursor = Cursors.SizeWE
Case "UpArrow"
DisplayArea.Cursor = Cursors.UpArrow
Case "WaitCursor"
DisplayArea.Cursor = Cursors.Wait
Case "Custom"
DisplayArea.Cursor = CustomCursor
End Select
' if the cursor scope is set to the entire application
' use OverrideCursor to force the cursor for all elements
If (cursorScopeElementOnly = False) Then
Mouse.OverrideCursor = DisplayArea.Cursor
End If
End Sub
Remarks
To suppress closing context menus, handlers of the event should mark it as handled.
To use this event as an EventTrigger in a style, you must reference the underlying service event identifier:
<EventTrigger RoutedEvent="ContextMenuService.ContextMenuClosing">
<!-- storyboard here ... -->
</EventTrigger>
(This usage is required because the event implementation on FrameworkContentElement that exposes the underlying service event does not correctly map the ContextMenuClosing identifier for use in triggers).
Routed Event Information
Identifier field | ContextMenuClosingEvent |
Routing strategy | Bubbling |
Delegate | ContextMenuEventHandler |