ContextMenuService Klasa
Definicja
Zapewnia implementację systemu na potrzeby wyświetlania ContextMenu .Provides the system implementation for displaying a ContextMenu.
public ref class ContextMenuService abstract sealed
public static class ContextMenuService
type ContextMenuService = class
Public Class ContextMenuService
- Dziedziczenie
-
ContextMenuService
Przykłady
Poniższy przykład przypisuje te same ContextMenu dwa przyciski i ustawia HasDropShadow Placement właściwości,, PlacementRectangle , i, HorizontalOffset VerticalOffset Aby ustawić na ContextMenu różne pozycje dla każdego przycisku.The following example assigns the same ContextMenu to two buttons and sets the HasDropShadow, Placement, PlacementRectangle, HorizontalOffset, and VerticalOffset properties to set the ContextMenu to different positions for each button.
<StackPanel>
<StackPanel.Resources>
<ContextMenu x:Key="myContextMenu">
<MenuItem Header="Item"/>
</ContextMenu>
</StackPanel.Resources>
<!--Both buttons use the same ContextMenu but use the
properties on ContextMenuService to position them
differently.-->
<Button ContextMenu="{StaticResource myContextMenu}"
ContextMenuService.HasDropShadow="False"
ContextMenuService.Placement="Relative"
ContextMenuService.HorizontalOffset="50"
ContextMenuService.VerticalOffset="-10">
button 1
</Button>
<Button ContextMenu="{StaticResource myContextMenu}"
ContextMenuService.HasDropShadow="True"
ContextMenuService.Placement="Right"
ContextMenuService.PlacementRectangle="0,0,30,30">
button 2
</Button>
</StackPanel>
Poniższy przykład pokazuje, jak używać usługi do wyświetlania ContextMenu na wyłączonym przycisku.The following example shows how to use the service to display a ContextMenu on a disabled button. Należy zauważyć, że ShowOnDisabled Właściwość jest ustawiana na przycisku, który jest elementem nadrzędnym menu kontekstowego.Notice that you set the ShowOnDisabled property on the button that is the parent of the context menu.
<Button Height="30" Content="Disabled Button" IsEnabled="False"
ContextMenuService.ShowOnDisabled="True">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Item 1"/>
<MenuItem Header="Item 2"/>
<MenuItem Header="Item 3"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
Uwagi
ContextMenuServiceKlasa zawiera dołączone właściwości, których można użyć do określenia wyglądu i położenia menu kontekstowego.The ContextMenuService class provides attached properties that can be used to specify the appearance and position of a context menu. Wiele właściwości w ContextMenuService klasie jest również zdefiniowanych przez ContextMenu .Many of the properties in the ContextMenuService class are also defined by the ContextMenu. Czasami wygodniejsze jest ustawienie właściwości przy użyciu ContextMenuService klasy niż przez ustawienie właściwości na ContextMenu .Sometimes it is more convenient to set the properties by using the ContextMenuService class than by setting the properties on a ContextMenu. Na przykład można utworzyć element, który ContextMenu ma być współużytkowany przez wiele elementów, ale Użyj ContextMenuService klasy, aby określić inne położenie ContextMenu dla każdego elementu.For example, you can create a ContextMenu to be shared by multiple elements, but use the ContextMenuService class to specify a different position of the ContextMenu for each element. Następujące właściwości są zdefiniowane przez ContextMenu ContextMenuService klasy i.The following properties are defined by the ContextMenu and ContextMenuService classes. Jeśli którakolwiek z tych właściwości jest ustawiona zarówno w ContextMenu , jak i ContextMenuService , wartość właściwości z ContextMenuService jest używana.If any of these properties are set on both ContextMenu and the ContextMenuService, the property value from the ContextMenuService is used.
Możesz również użyć ContextMenuService do wyświetlania menu dla elementów wyłączonych.You can also use the ContextMenuService to display menus on disabled items.
Pola
ContextMenuClosingEvent |
Identyfikuje ContextMenuClosing zdarzenie kierowane.Identifies the ContextMenuClosing routed event. |
ContextMenuOpeningEvent |
Identyfikuje ContextMenuOpening dołączone zdarzenie.Identifies the ContextMenuOpening attached event. |
ContextMenuProperty |
Identyfikuje ContextMenu załączoną właściwość.Identifies the ContextMenu attached property. |
HasDropShadowProperty |
Identyfikuje HasDropShadow załączoną właściwość.Identifies the HasDropShadow attached property. |
HorizontalOffsetProperty |
Identyfikuje HorizontalOffset załączoną właściwość.Identifies the HorizontalOffset attached property. |
IsEnabledProperty |
Identyfikuje IsEnabled załączoną właściwość.Identifies the IsEnabled attached property. |
PlacementProperty |
Identyfikuje Placement załączoną właściwość.Identifies the Placement attached property. |
PlacementRectangleProperty |
Identyfikuje PlacementRectangle załączoną właściwość.Identifies the PlacementRectangle attached property. |
PlacementTargetProperty |
Identyfikuje PlacementTarget załączoną właściwość.Identifies the PlacementTarget attached property. |
ShowOnDisabledProperty |
Identyfikuje ShowOnDisabled załączoną właściwość.Identifies the ShowOnDisabled attached property. |
VerticalOffsetProperty |
Identyfikuje VerticalOffset załączoną właściwość.Identifies the VerticalOffset attached property. |
Właściwości dołączone
ContextMenu |
Pobiera lub ustawia zawartość ContextMenu .Gets or sets the content of a ContextMenu. |
HasDropShadow |
Pobiera lub ustawia wartość wskazującą, czy ContextMenu ma włączony efekt cieniowania.Gets or sets a value that indicates whether the ContextMenu has the drop shadow effect enabled. |
HorizontalOffset |
Pobiera lub ustawia wartość wskazującą, gdzie wzdłuż kierunku x ma zostać umieszczony w ContextMenu odniesieniu do kontrolki nadrzędnej.Gets or sets a value that indicates where along the x-direction to place the ContextMenu with respect to the parent control. |
IsEnabled |
Pobiera lub ustawia wartość wskazującą, czy ContextMenu można wyświetlić element.Gets or sets a value that indicates whether the ContextMenu can be shown. |
Placement |
Pobiera lub ustawia wartość określającą położenie ContextMenu względem PlacementTarget lub PlacementRectangle .Gets or sets a value that specifies the placement of the ContextMenu relative to the PlacementTarget or PlacementRectangle. |
PlacementRectangle |
Pobiera lub ustawia obszar, względem którego jest ustawione menu kontekstowe, gdy zostanie ono otwarte.Gets or sets the area relative to which the context menu is positioned when it opens. |
PlacementTarget |
Pobiera lub ustawia kontrolkę nadrzędną ContextMenu .Gets or sets the parent control of the ContextMenu. |
ShowOnDisabled |
Pobiera lub ustawia wartość wskazującą, czy ContextMenu powinien być pokazywany, gdy jego element nadrzędny jest wyszarzony.Gets or sets a value that indicates whether the ContextMenu should be shown when its parent is grayed out. |
VerticalOffset |
Pobiera lub ustawia wartość wskazującą, gdzie wzdłuż kierunku y ma zostać umieszczony w ContextMenu odniesieniu do kontrolki nadrzędnej.Gets or sets a value that indicates where along the y-direction to place the ContextMenu with respect to the parent control. |
Metody
AddContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) |
Dodaje procedurę obsługi dla ContextMenuClosing dołączonego zdarzenia.Adds a handler for the ContextMenuClosing attached event. |
AddContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) |
Dodaje procedurę obsługi dla ContextMenuOpening dołączonego zdarzenia.Adds a handler for the ContextMenuOpening attached event. |
GetContextMenu(DependencyObject) |
Pobiera wartość ContextMenu właściwości określonego obiektu.Gets the value of the ContextMenu property of the specified object. |
GetHasDropShadow(DependencyObject) |
Pobiera wartość wskazującą, czy ContextMenu ma cień.Gets a value that indicates whether the ContextMenu has a drop shadow. |
GetHorizontalOffset(DependencyObject) |
Pobiera wartość HorizontalOffset właściwości określonego obiektu.Gets the value of the HorizontalOffset property of the specified object. |
GetIsEnabled(DependencyObject) |
Pobiera wartość IsEnabled właściwości określonego obiektu.Gets the value of the IsEnabled property of the specified object. |
GetPlacement(DependencyObject) |
Pobiera wartość Placement właściwości określonego obiektu.Gets the value of the Placement property of the specified object. |
GetPlacementRectangle(DependencyObject) |
Pobiera wartość PlacementRectangle właściwości określonego obiektu.Gets the value of the PlacementRectangle property of the specified object. |
GetPlacementTarget(DependencyObject) |
Pobiera wartość PlacementTarget właściwości określonego obiektu.Gets the value of the PlacementTarget property of the specified object. |
GetShowOnDisabled(DependencyObject) |
Pobiera wartość ShowOnDisabled właściwości określonego obiektu.Gets the value of the ShowOnDisabled property of the specified object. |
GetVerticalOffset(DependencyObject) |
Pobiera wartość VerticalOffset właściwości określonego obiektu.Gets the value of the VerticalOffset property of the specified object. |
RemoveContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) |
Usuwa procedurę obsługi dla ContextMenuClosing dołączonego zdarzenia.Removes a handler for the ContextMenuClosing attached event. |
RemoveContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) |
Usuwa procedurę obsługi dla ContextMenuOpening dołączonego zdarzenia.Removes a handler for the ContextMenuOpening attached event. |
SetContextMenu(DependencyObject, ContextMenu) |
Ustawia wartość ContextMenu właściwości określonego obiektu.Sets the value of the ContextMenu property of the specified object. |
SetHasDropShadow(DependencyObject, Boolean) |
Ustawia wartość wskazującą, czy ContextMenu ma cień.Sets a value that indicates whether the ContextMenu has a drop shadow. |
SetHorizontalOffset(DependencyObject, Double) |
Ustawia wartość HorizontalOffset właściwości określonego obiektu.Sets the value of the HorizontalOffset property of the specified object. |
SetIsEnabled(DependencyObject, Boolean) |
Ustawia wartość IsEnabled właściwości określonego obiektu.Sets the value of the IsEnabled property of the specified object. |
SetPlacement(DependencyObject, PlacementMode) |
Ustawia wartość Placement właściwości określonego obiektu.Sets the value of the Placement property of the specified object. |
SetPlacementRectangle(DependencyObject, Rect) |
Ustawia wartość PlacementRectangle właściwości określonego obiektu.Sets the value of the PlacementRectangle property of the specified object. |
SetPlacementTarget(DependencyObject, UIElement) |
Ustawia wartość PlacementTarget właściwości określonego obiektu.Sets the value of the PlacementTarget property of the specified object. |
SetShowOnDisabled(DependencyObject, Boolean) |
Ustawia wartość ShowOnDisabled właściwości określonego obiektu.Sets the value of the ShowOnDisabled property of the specified object. |
SetVerticalOffset(DependencyObject, Double) |
Ustawia wartość VerticalOffset właściwości określonego obiektu.Sets the value of the VerticalOffset property of the specified object. |
Zdarzenia dołączone
ContextMenuClosing |
Występuje po ContextMenu zamknięciu.Occurs when the ContextMenu closes. |
ContextMenuOpening |
Występuje po ContextMenu otwarciu.Occurs when the ContextMenu opens. |