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就会IsEnabledfalse有一个。 尝试设置此值也可能被返回 IsEnabledCore的值重写。

未启用的元素不参与命中测试或焦点,因此不会是输入事件的源。

依赖项属性信息

标识符字段 IsEnabledProperty
元数据属性设置为 true

适用于

另请参阅