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屬於<Style.Triggers > 區塊。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樣式控制項將會報告IsMouseOver作為true如果在滑鼠位於任何地方網格的幾何,包括任何ListBoxItemFor 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. 例如,您可以處理MouseEnterMouseMove,和IsMouseDirectlyOverChangedFor 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

適用於