UIElement.IsMouseOver UIElement.IsMouseOver UIElement.IsMouseOver UIElement.IsMouseOver Property

定義

取得值,指出滑鼠指標是否在這個項目上方 (包括視覺化樹狀中的子項目)。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.

public:
 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"/>
</Trigger>

備註

控制項通常是複合的, 因此控制項內的各種元素 (視覺化樹狀結構) 都會針對包含控制項來報告滑鼠狀態。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. ListBox例如, 當滑鼠在其幾何的任何true位置 (包括 any ListBoxItem) 時, 樣式控制項將會報告IsMouseOverFor 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 true即使滑鼠尚未明顯移動也一樣。This 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 None

適用於