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 です。

次の例は、1 つのボタンのハンドラーを示しています。このハンドラーを実行すると、別の名前付きボタンb1に設定IsEnabledfalseされます。

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 影響を受けます。 そのため、ここで示す既定値は有効でない場合があります。 たとえば、スクロール バーをサポートする必要がないと判断された場合は常に a ScrollBar IsEnabled false になります。 この値を設定しようとすると、返される値によってオーバーライドされる IsEnabledCore可能性もあります。

有効になっていない要素はヒット テストやフォーカスに参加しないため、入力イベントのソースになりません。

依存プロパティ情報

識別子フィールド IsEnabledProperty
に設定されたメタデータ プロパティ true なし

適用対象

こちらもご覧ください