UIElement.IsMouseOver 属性


获取一个值,该值指示鼠标指针是否位于此元素(包括可视化树中的子元素)的上方。Gets a value indicating whether the mouse pointer is located over this element (including child elements in the visual tree). 这是依赖项属性。This is a dependency property.

 property bool IsMouseOver { bool get(); };
public bool IsMouseOver { get; }
member this.IsMouseOver : bool
Public ReadOnly Property IsMouseOver As Boolean


如果鼠标指针位于该元素或其子元素上方,则为 true;否则为 falsetrue if mouse pointer is over the element or its child elements; otherwise, false. 默认值为 falseThe default is false.



下面的示例将此属性作为 <样式 Trigger的一部分的属性类型引用。触发器 > block。The following example references this property as the property type of a Trigger, part of a <Style.Triggers> block. 如果鼠标位于控件上方,控件文本将变为蓝色,光标将变为手形。If the mouse is over the control, the control text turns blue and the cursor becomes a hand.

<Trigger Property="IsMouseOver" Value="true">
  <Setter Property="Foreground" Value="Blue" />
  <Setter Property="Cursor" Value="Hand"/>


通常,控件是复合的,因此控件内的各种元素(可视化树)都将报告包含控件的鼠标状态。Typically, controls are composited such that the various elements inside the control (the visual tree) will all report the mouse state for the containing control. 例如,如果鼠标位于其几何图形上的任意位置(包括任何 ListBoxItem),则 ListBox 样式控件将报告 IsMouseOvertrueFor example, a ListBox style control will report IsMouseOver as true if the mouse is anywhere over its geometry, including any ListBoxItem.

尽管不存在类似的 "IsMouseOverChanged" 事件,但有几个类似的事件。Although an analogous "IsMouseOverChanged" event does not exist, several similar events do. 例如,可以处理 MouseEnterMouseMoveIsMouseDirectlyOverChangedFor example, you can handle MouseEnter, MouseMove, and IsMouseDirectlyOverChanged.

如果此元素捕获鼠标,此属性将保持 true,直到鼠标捕获丢失,并且鼠标指针离开元素边界。If this element captures the mouse, this property remains true until mouse capture is lost and the mouse pointer leaves the element bounds.

某些控件有意捕获鼠标上某些不直接涉及鼠标的操作。Some controls deliberately capture the mouse on certain actions that do not appear to directly involve the mouse. 即使鼠标没有明显移动,这也会导致 IsMouseOver trueThis can lead to IsMouseOver being true even though the mouse has not apparently moved.

依赖项属性信息Dependency Property Information

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