UIElement.IsEnabled 屬性

定義

取得或設定值,指出使用者介面 (UI) 中是否啟用這個專案。 這是相依性屬性。

C#
public bool IsEnabled { get; set; }

屬性值

如果專案已啟用,true;否則,false。 預設值為 true

範例

下列範例顯示一個按鈕上的處理程式,當執行時,會在另一個具名按鈕上設定 IsEnabledfalseb1

C#
public partial class RoutedEventAddRemoveHandler {
    void MakeButton(object sender, RoutedEventArgs e)
    {
        Button b2 = new Button();
        b2.Content = "New Button";
        // Associate event handler to the button. You can remove the event 
        // handler using "-=" syntax rather than "+=".
        b2.Click  += new RoutedEventHandler(Onb2Click);
        root.Children.Insert(root.Children.Count, b2);
        DockPanel.SetDock(b2, Dock.Top);
        text1.Text = "Now click the second button...";
        b1.IsEnabled = false;
    }
    void Onb2Click(object sender, RoutedEventArgs e)
    {
        text1.Text = "New Button (b2) Was Clicked!!";
    }

備註

請注意,此屬性會受到特定元素上 IsEnabledCore 的類別特定實作所影響,通常是在運行時間。 因此,此處所列的預設值有時無效。 例如,每當判斷不需要支援滾動條時,就會 IsEnabledfalseScrollBar。 嘗試設定此值也可能由 IsEnabledCore所傳回的值覆寫。

未啟用的專案不會參與點擊測試或焦點,因此不會是輸入事件的來源。

相依性屬性資訊

標識元欄位 IsEnabledProperty
設定為 true 的元數據屬性 沒有

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱