ContextMenu.HorizontalOffset 属性


获取或设置目标原点与弹出项对齐点之间的水平距离。Get or sets the horizontal distance between the target origin and the popup alignment point.

 property double HorizontalOffset { double get(); void set(double value); };
public double HorizontalOffset { get; set; }
member this.HorizontalOffset : double with get, set
Public Property HorizontalOffset As Double


目标原点与弹出项对齐点之间的水平距离。The horizontal distance between the target origin and the popup alignment point. 有关目标原点和 popup 对齐点的信息, 请参阅Popup 放置行为For information about the target origin and popup alignment point, see Popup Placement Behavior. 默认值为 0。The default is 0.



下面的示例演示如何使用HorizontalOffset属性ContextMenu使在指定位置 (相对于其按钮父级) 打开。The following example shows how to use the HorizontalOffset property to cause a ContextMenu to open at a specified location in relation to its button parent.

<ContextMenu HorizontalOffset="50" VerticalOffset="50" HasDropShadow="false">


ContextMenu Placement PlacementRectangle通过设置、、HorizontalOffset、和VerticalOffsetProperty属性, 可以定位。 PlacementTargetYou can position a ContextMenu by setting the PlacementTarget, PlacementRectangle, Placement, HorizontalOffset, and VerticalOffsetProperty properties. 这些属性的行为与对Popup的行为相同。These properties behave the same as they do for a Popup. 有关详细信息,请参阅 Popup 放置行为For more information, see Popup Placement Behavior.

依赖项属性信息Dependency Property Information

标识符字段Identifier field HorizontalOffsetProperty
元数据属性设置为trueMetadata properties set to true NoneNone

XAML 属性用法XAML Attribute Usage

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



Double值的字符串表示形式。String representation of a Double value. 这会被解释为与设备无关的单位(1/96 英寸)device-independent unit (1/96th inch)度量值。This is interpreted as a 与设备无关的单位(1/96 英寸)device-independent unit (1/96th inch) measurement. 字符串不需要显式包含小数点。Strings need not explicitly include decimal points. 例如, 的值1是可接受的。For instance a value of 1 is acceptable.

与属性Double值部分中提到的范围限制相同。The same Double range restrictions as mentioned in the Property Value section apply.

如上所述的双精度值, 后跟以下单元声明字符串之一px:、 incmptA double value as described above, followed by one of the following unit declaration strings: px, in, cm, pt.

px(默认值) 是与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit)px (default) is 与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit)

in为英寸;1in = = 96pxin is inches; 1in==96px

cm为厘米;1cm = = (96/2.54) pxcm is centimeters; 1cm==(96/2.54) px

pt为点;1pt = = (96/72) pxpt is points; 1pt==(96/72) px

注意在许多情况下, double 可以设置为 auto, 但ContextMenu如果偏移量设置为 auto, 则不会显示。Note In many cases a double may be set to Auto but a ContextMenu will not appear if the offsets are set to Auto.