ButtonBase.IsPressed 屬性

定義

取得值,這個值表示 ButtonBase 目前是否已啟動。Gets a value that indicates whether a ButtonBase is currently activated.

public:  property bool IsPressed {  public:
bool get(); protected:
 void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool IsPressed { get; protected set; }
member this.IsPressed : bool with get, set
Public Property IsPressed As Boolean

屬性值

如果 ButtonBase 已啟動則為 true,否則為 falsetrue if the ButtonBase is activated; otherwise false. 預設為 falseThe default is false.

屬性

範例

這個範例示範如何使用觸發程式樣式中的 IsPressed 屬性。This example shows how to use the IsPressed property in a trigger style.

<Style x:Key="Triggers" TargetType="Button">
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="true">
      <Setter Property = "Background" Value="Red"/>
    </Trigger>
    <Trigger Property="IsPressed" Value="true">
      <Setter Property = "Foreground" Value="Green"/>
    </Trigger>
  </Style.Triggers>
</Style>

備註

IsPressed 是按鈕的狀態,表示按下滑鼠左鍵或空格鍵已按下按鈕。IsPressed is the state of a button that indicates the left mouse button or SPACEBAR is pressed over the button. trueIsPressed 時,控制項會捕捉滑鼠。When IsPressed is true, the control captures the mouse. 因此,控制項將會引發滑鼠事件,例如 MouseEnterIsMouseDirectlyOverChangedAs a result, the control will raise mouse events such as MouseEnter and IsMouseDirectlyOverChanged. 請注意,使用 AccessText 或 ENTER 並不會變更 IsPressed 或捕捉滑鼠,但會引發 Click 事件。Note that using the AccessText or ENTER does not change IsPressed or capture the mouse, but is does raise the Click event.

從 .NET Framework 3.0 版 Service Pack 1 開始,IsPressed 具有受保護的 setter。Starting with the .NET Framework version 3.0 Service Pack 1, IsPressed has a protected setter. 若要使用此功能,您的應用程式應以 .NET Framework 版本3.5 為目標。To use this functionality, your application should target the .NET Framework version 3.5. 如需詳細資訊,請參閱版本和相依性For more information, see Versions and Dependencies.

相依性屬性資訊Dependency Property Information

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

適用於