UIElement.IsEnabled 屬性

定義

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

public:
 property bool IsEnabled { bool get(); void set(bool value); };
public bool IsEnabled { get; set; }
member this.IsEnabled : bool with get, set
Public Property IsEnabled As Boolean

屬性值

Boolean

如果啟用這個項目,則為 true;否則為 false。 預設值是 true

範例

下列範例顯示一個按鈕上的處理常式,當執行時,會在另一個具名按鈕 b1 上設定 。 IsEnabled false

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!!";
    }
Public Partial Class RoutedEventAddRemoveHandler
    Private Sub MakeButton(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim b2 As Button = New Button()
        b2.Content = "New Button"
        AddHandler b2.Click, AddressOf Onb2Click
        root.Children.Insert(root.Children.Count, b2)
        DockPanel.SetDock(b2, Dock.Top)
        text1.Text = "Now click the second button..."
        b1.IsEnabled = False
    End Sub
    Private Sub Onb2Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        text1.Text = "New Button (b2) Was Clicked!!"
    End Sub

備註

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

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

相依性屬性資訊

識別碼欄位 IsEnabledProperty
設定為 的中繼資料屬性 true

適用於

另請參閱