ContextMenuService ContextMenuService ContextMenuService ContextMenuService Class

Definición

Proporciona la implementación del sistema para mostrar 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
Herencia
ContextMenuServiceContextMenuServiceContextMenuServiceContextMenuService

Ejemplos

En el ejemplo siguiente se asigna el mismo ContextMenu a dos botones y se establece la HasDropShadow, Placement, PlacementRectangle, HorizontalOffset, y VerticalOffset propiedades para establecer el ContextMenu en posiciones diferentes para cada botón.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>

El ejemplo siguiente muestra cómo usar el servicio para mostrar un ContextMenu en un botón deshabilitado.The following example shows how to use the service to display a ContextMenu on a disabled button. Tenga en cuenta que configuró el ShowOnDisabled propiedad en el botón que es el elemento primario del menú contextual.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>

Comentarios

La ContextMenuService clase proporciona propiedades adjuntas que pueden utilizarse para especificar la apariencia y la posición de un menú contextual.The ContextMenuService class provides attached properties that can be used to specify the appearance and position of a context menu. Muchas de las propiedades de la ContextMenuService clase también se definen mediante el ContextMenu.Many of the properties in the ContextMenuService class are also defined by the ContextMenu. A veces resulta más conveniente establecer las propiedades mediante el ContextMenuService estableciendo las propiedades en la clase que un ContextMenu.Sometimes it is more convenient to set the properties by using the ContextMenuService class than by setting the properties on a ContextMenu. Por ejemplo, puede crear un ContextMenu para ser compartidos por varios elementos, pero usar el ContextMenuService clase para especificar una posición diferente de la ContextMenu para cada elemento.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. Las siguientes propiedades se definen mediante la ContextMenu y ContextMenuService clases.The following properties are defined by the ContextMenu and ContextMenuService classes. Si cualquiera de estas propiedades se establecen en ambos ContextMenu y ContextMenuService, el valor de propiedad de la ContextMenuService se utiliza.If any of these properties are set on both ContextMenu and the ContextMenuService, the property value from the ContextMenuService is used.

También puede usar el ContextMenuService para mostrar los menús en elementos deshabilitados.You can also use the ContextMenuService to display menus on disabled items.

Campos

ContextMenuClosingEvent ContextMenuClosingEvent ContextMenuClosingEvent ContextMenuClosingEvent

Identifica el evento enrutado ContextMenuClosing.Identifies the ContextMenuClosing routed event.

ContextMenuOpeningEvent ContextMenuOpeningEvent ContextMenuOpeningEvent ContextMenuOpeningEvent

Identifica el evento adjunto ContextMenuOpening.Identifies the ContextMenuOpening attached event.

ContextMenuProperty ContextMenuProperty ContextMenuProperty ContextMenuProperty

Identifica la propiedad adjunta ContextMenu.Identifies the ContextMenu attached property.

HasDropShadowProperty HasDropShadowProperty HasDropShadowProperty HasDropShadowProperty

Identifica la propiedad adjunta HasDropShadow.Identifies the HasDropShadow attached property.

HorizontalOffsetProperty HorizontalOffsetProperty HorizontalOffsetProperty HorizontalOffsetProperty

Identifica la propiedad adjunta HorizontalOffset.Identifies the HorizontalOffset attached property.

IsEnabledProperty IsEnabledProperty IsEnabledProperty IsEnabledProperty

Identifica la propiedad adjunta IsEnabled.Identifies the IsEnabled attached property.

PlacementProperty PlacementProperty PlacementProperty PlacementProperty

Identifica la propiedad adjunta Placement.Identifies the Placement attached property.

PlacementRectangleProperty PlacementRectangleProperty PlacementRectangleProperty PlacementRectangleProperty

Identifica la propiedad adjunta PlacementRectangle.Identifies the PlacementRectangle attached property.

PlacementTargetProperty PlacementTargetProperty PlacementTargetProperty PlacementTargetProperty

Identifica la propiedad adjunta PlacementTarget.Identifies the PlacementTarget attached property.

ShowOnDisabledProperty ShowOnDisabledProperty ShowOnDisabledProperty ShowOnDisabledProperty

Identifica la propiedad adjunta ShowOnDisabled.Identifies the ShowOnDisabled attached property.

VerticalOffsetProperty VerticalOffsetProperty VerticalOffsetProperty VerticalOffsetProperty

Identifica la propiedad adjunta VerticalOffset.Identifies the VerticalOffset attached property.

Propiedades adjuntas

ContextMenu ContextMenu ContextMenu ContextMenu

Obtiene o establece el contenido de ContextMenu.Gets or sets the content of a ContextMenu.

HasDropShadow HasDropShadow HasDropShadow HasDropShadow

Obtiene o establece un valor que indica si ContextMenu tiene el efecto de sombra habilitado.Gets or sets a value that indicates whether the ContextMenu has the drop shadow effect enabled.

HorizontalOffset HorizontalOffset HorizontalOffset HorizontalOffset

Obtiene o establece un valor que indica dónde se debe colocar a lo largo de la dirección x ContextMenu con respecto al control principal.Gets or sets a value that indicates where along the x-direction to place the ContextMenu with respect to the parent control.

IsEnabled IsEnabled IsEnabled IsEnabled

Obtiene o establece un valor que indica si se puede mostrar ContextMenu.Gets or sets a value that indicates whether the ContextMenu can be shown.

Placement Placement Placement Placement

Obtiene o establece un valor que especifica la posición de ContextMenu en relación con PlacementTarget o PlacementRectangle.Gets or sets a value that specifies the placement of the ContextMenu relative to the PlacementTarget or PlacementRectangle.

PlacementRectangle PlacementRectangle PlacementRectangle PlacementRectangle

Obtiene o establece el área relativa a la cual se coloca el menú contextual cuando se abre.Gets or sets the area relative to which the context menu is positioned when it opens.

PlacementTarget PlacementTarget PlacementTarget PlacementTarget

Obtiene o establece el control principal de ContextMenu.Gets or sets the parent control of the ContextMenu.

ShowOnDisabled ShowOnDisabled ShowOnDisabled ShowOnDisabled

Obtiene o establece un valor que indica si se debe mostrar ContextMenu cuando su elemento primario está deshabilitado.Gets or sets a value that indicates whether the ContextMenu should be shown when its parent is grayed out.

VerticalOffset VerticalOffset VerticalOffset VerticalOffset

Obtiene o establece un valor que indica dónde se debe colocar a lo largo de la dirección y ContextMenu con respecto al control principal.Gets or sets a value that indicates where along the y-direction to place the ContextMenu with respect to the parent control.

Métodos

AddContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler)

Agrega un controlador para el evento adjunto ContextMenuClosing.Adds a handler for the ContextMenuClosing attached event.

AddContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) AddContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler)

Agrega un controlador para el evento adjunto ContextMenuOpening.Adds a handler for the ContextMenuOpening attached event.

GetContextMenu(DependencyObject) GetContextMenu(DependencyObject) GetContextMenu(DependencyObject) GetContextMenu(DependencyObject)

Obtiene el valor de la propiedad ContextMenu del objeto especificado.Gets the value of the ContextMenu property of the specified object.

GetHasDropShadow(DependencyObject) GetHasDropShadow(DependencyObject) GetHasDropShadow(DependencyObject) GetHasDropShadow(DependencyObject)

Obtiene un valor que indica si ContextMenu tiene un efecto de sombra.Gets a value that indicates whether the ContextMenu has a drop shadow.

GetHorizontalOffset(DependencyObject) GetHorizontalOffset(DependencyObject) GetHorizontalOffset(DependencyObject) GetHorizontalOffset(DependencyObject)

Obtiene el valor de la propiedad HorizontalOffset del objeto especificado.Gets the value of the HorizontalOffset property of the specified object.

GetIsEnabled(DependencyObject) GetIsEnabled(DependencyObject) GetIsEnabled(DependencyObject) GetIsEnabled(DependencyObject)

Obtiene el valor de la propiedad IsEnabled del objeto especificado.Gets the value of the IsEnabled property of the specified object.

GetPlacement(DependencyObject) GetPlacement(DependencyObject) GetPlacement(DependencyObject) GetPlacement(DependencyObject)

Obtiene el valor de la propiedad Placement del objeto especificado.Gets the value of the Placement property of the specified object.

GetPlacementRectangle(DependencyObject) GetPlacementRectangle(DependencyObject) GetPlacementRectangle(DependencyObject) GetPlacementRectangle(DependencyObject)

Obtiene el valor de la propiedad PlacementRectangle del objeto especificado.Gets the value of the PlacementRectangle property of the specified object.

GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject)

Obtiene el valor de la propiedad PlacementTarget del objeto especificado.Gets the value of the PlacementTarget property of the specified object.

GetShowOnDisabled(DependencyObject) GetShowOnDisabled(DependencyObject) GetShowOnDisabled(DependencyObject) GetShowOnDisabled(DependencyObject)

Obtiene el valor de la propiedad ShowOnDisabled del objeto especificado.Gets the value of the ShowOnDisabled property of the specified object.

GetVerticalOffset(DependencyObject) GetVerticalOffset(DependencyObject) GetVerticalOffset(DependencyObject) GetVerticalOffset(DependencyObject)

Obtiene el valor de la propiedad VerticalOffset del objeto especificado.Gets the value of the VerticalOffset property of the specified object.

RemoveContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuClosingHandler(DependencyObject, ContextMenuEventHandler)

Quita un controlador del evento adjunto ContextMenuClosing.Removes a handler for the ContextMenuClosing attached event.

RemoveContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler) RemoveContextMenuOpeningHandler(DependencyObject, ContextMenuEventHandler)

Quita un controlador del evento adjunto ContextMenuOpening.Removes a handler for the ContextMenuOpening attached event.

SetContextMenu(DependencyObject, ContextMenu) SetContextMenu(DependencyObject, ContextMenu) SetContextMenu(DependencyObject, ContextMenu) SetContextMenu(DependencyObject, ContextMenu)

Establece el valor de la propiedad ContextMenu del objeto especificado.Sets the value of the ContextMenu property of the specified object.

SetHasDropShadow(DependencyObject, Boolean) SetHasDropShadow(DependencyObject, Boolean) SetHasDropShadow(DependencyObject, Boolean) SetHasDropShadow(DependencyObject, Boolean)

Establece un valor que indica si ContextMenu tiene un efecto de sombra.Sets a value that indicates whether the ContextMenu has a drop shadow.

SetHorizontalOffset(DependencyObject, Double) SetHorizontalOffset(DependencyObject, Double) SetHorizontalOffset(DependencyObject, Double) SetHorizontalOffset(DependencyObject, Double)

Establece el valor de la propiedad HorizontalOffset del objeto especificado.Sets the value of the HorizontalOffset property of the specified object.

SetIsEnabled(DependencyObject, Boolean) SetIsEnabled(DependencyObject, Boolean) SetIsEnabled(DependencyObject, Boolean) SetIsEnabled(DependencyObject, Boolean)

Establece el valor de la propiedad IsEnabled del objeto especificado.Sets the value of the IsEnabled property of the specified object.

SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode)

Establece el valor de la propiedad Placement del objeto especificado.Sets the value of the Placement property of the specified object.

SetPlacementRectangle(DependencyObject, Rect) SetPlacementRectangle(DependencyObject, Rect) SetPlacementRectangle(DependencyObject, Rect) SetPlacementRectangle(DependencyObject, Rect)

Establece el valor de la propiedad PlacementRectangle del objeto especificado.Sets the value of the PlacementRectangle property of the specified object.

SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement)

Establece el valor de la propiedad PlacementTarget del objeto especificado.Sets the value of the PlacementTarget property of the specified object.

SetShowOnDisabled(DependencyObject, Boolean) SetShowOnDisabled(DependencyObject, Boolean) SetShowOnDisabled(DependencyObject, Boolean) SetShowOnDisabled(DependencyObject, Boolean)

Establece el valor de la propiedad ShowOnDisabled del objeto especificado.Sets the value of the ShowOnDisabled property of the specified object.

SetVerticalOffset(DependencyObject, Double) SetVerticalOffset(DependencyObject, Double) SetVerticalOffset(DependencyObject, Double) SetVerticalOffset(DependencyObject, Double)

Establece el valor de la propiedad VerticalOffset del objeto especificado.Sets the value of the VerticalOffset property of the specified object.

Eventos adjuntos

ContextMenuClosing ContextMenuClosing ContextMenuClosing ContextMenuClosing

Se produce cuando se cierra el control ContextMenu.Occurs when the ContextMenu closes.

ContextMenuOpening ContextMenuOpening ContextMenuOpening ContextMenuOpening

Se produce cuando se abre ContextMenu.Occurs when the ContextMenu opens.

Se aplica a

Consulte también: