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的屬性型別,<樣式的一部分。會觸發 > 區塊。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 樣式控制項就會將 IsMouseOver 報告為 trueFor 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. 這可能會導致 trueIsMouseOver,即使滑鼠尚未明顯移動也一樣。This can lead to IsMouseOver being true even though the mouse has not apparently moved.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field IsMouseOverProperty
設定為 true 的中繼資料屬性Metadata properties set to true None