UIElement.IsEnabled UIElement.IsEnabled UIElement.IsEnabled UIElement.IsEnabled Property

定義

取得或設定值,這個值表示 使用者介面 (UI)user interface (UI) 中是否已啟用這個項目。Gets or sets a value indicating whether this element is enabled in the 使用者介面 (UI)user interface (UI). 這是相依性屬性。This is a dependency property.

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

屬性值

如果已啟用該項目則為 true,否則為 falsetrue if the element is enabled; otherwise, false. 預設值為 trueThe default value is true.

範例

下列範例顯示一個按鈕上的處理常式, 當執行時, IsEnabled它會在另b1一個已命名的按鈕上設定falseThe following example shows a handler on one button that when executed will set IsEnabled false on another named button b1.

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特定的實作為影響, 通常是在執行時間。Note that this property is influenced by class-specific implementations of IsEnabledCore on particular elements, often at runtime. 因此, 此處所列的預設值有時不會生效。Therefore, the default value listed here is sometimes not effective. 比方說, ScrollBar false每當判斷不IsEnabled需要支援捲軸時, 就會是。For instance, a ScrollBar will be IsEnabled false whenever it is determined that there is no need to support a scrollbar. 嘗試設定這個值也可能會由傳回IsEnabledCore的值覆寫。Attempting to set this value will also potentially be overridden by the value returned by IsEnabledCore.

未啟用的元素不會參與點擊測試或焦點, 因此不會成為輸入事件的來源。Elements that are not enabled do not participate in hit testing or focus and therefore will not be sources of input events.

相依性屬性資訊Dependency Property Information

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

適用於

另請參閱