語言

ContextMenuService.VerticalOffset 附加屬性

定義

取得或設定一個值,指示該在 y 方向上相 ContextMenu 對於父控制項的位置。

see GetVerticalOffset, and SetVerticalOffset
see GetVerticalOffset, and SetVerticalOffset
see GetVerticalOffset, and SetVerticalOffset

範例

以下範例將相同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 價值觀
識別碼欄位 VerticalOffsetProperty
元資料屬性設為 true None

XAML 屬性使用方式

<object VerticalOffset="double"/>
- or -
<object VerticalOffset="qualifiedDouble"/>

XAML 值

雙重Double

一個數值的 Double 字串表示。 此測量被解釋為與裝置無關的單位(1/96英吋)。 字串不必明確包含小數點。 例如 1 ,值為可接受。

取得雙重資格如上所述的雙倍值,接著是以下其中一個單位宣告字串:px, in, cmpt, 。

px (預設)為裝置無關單位(每單位 1/96 吋)

in 是英吋;1in==96px

cm 是公分;1cm==(96/2.54) px

pt 是分數;1pt==(96/72) px

適用於

另請參閱