ContextMenuService.Placement Właściwość dołączona

Definicja

Pobiera lub ustawia wartość, która określa położenie ContextMenu względem obiektu PlacementTarget lub PlacementRectangle.

see GetPlacement, and SetPlacement
see GetPlacement, and SetPlacement
see GetPlacement, and SetPlacement

Przykłady

Poniższy przykład przypisuje te same ContextMenu przyciski do dwóch przycisków i ustawia HasDropShadowwłaściwości , Placement, PlacementRectangle, HorizontalOffseti VerticalOffset w celu ustawienia ContextMenu wartości na różne pozycje dla każdego przycisku.

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

Uwagi

Element można ustawićContextMenu, ustawiając właściwości , , PlacementPlacementRectangle, HorizontalOffseti VerticalOffsetProperty .PlacementTarget Te właściwości zachowują się tak samo jak w przypadku elementu Popup. Aby uzyskać więcej informacji, zobacz Zachowanie umieszczania w oknie podręcznym.

Informacje dotyczące właściwości zależności

Pole identyfikatora PlacementProperty
Właściwości metadanych ustawione na true Brak

Dotyczy

Zobacz też