ContextMenuService.PlacementRectangle Присоединенное свойство

Определение

Получает или задает область, относительно которой позиционируется контекстное меню при открытии.

see GetPlacementRectangle, and SetPlacementRectangle
see GetPlacementRectangle, and SetPlacementRectangle
see GetPlacementRectangle, and SetPlacementRectangle

Примеры

В следующем примере две кнопки назначаются ContextMenu одинаково и свойства HasDropShadow, PlacementRectanglePlacement, , HorizontalOffsetи VerticalOffset , чтобы задать ContextMenu разные позиции для каждой кнопки.

<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>

Комментарии

Можно расположить, задав PlacementTargetсвойства , PlacementRectangle, PlacementHorizontalOffset, и VerticalOffsetProperty .ContextMenu Эти свойства ведут себя так же, как и для Popup. Дополнительные сведения см. в разделе Поведение при размещении контекстного меню.

Сведения о свойстве зависимостей

Поле идентификатора PlacementRectangleProperty
Для свойств метаданных задано значение true Нет

Применяется к

См. также раздел