語言

ContextMenuService.PlacementRectangle 附加屬性

定義

它會取得或設定右鍵選單開啟時相對於位置的區域。

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

範例

以下範例將相同ContextMenu位置分配給兩個按鈕,並將 HasDropShadow、 Placement、 PlacementRectangle、 HorizontalOffsetVerticalOffset 和 屬性設定為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>

備註

你可以透過設定 ContextMenu、 PlacementTarget、 PlacementRectangle、 Placement和 HorizontalOffset 屬性來定位 aVerticalOffsetProperty。 這些性質的行為與 Popup中相同。 更多資訊,請參閱 彈出式元件的擺放行為。

相依財產資訊

Item 價值觀
識別碼欄位 PlacementRectangleProperty
元資料屬性設為 true None

適用於

另請參閱