言語

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

プロパティ値

true 要素が有効な場合は〘。それ以外の場合は false。 既定値は true です。

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

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

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

依存関係プロパティ情報

品目 価値
識別子フィールド IsEnabledProperty
に設定されたメタデータ プロパティ true None

適用対象

こちらもご覧ください