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. 例如, false每当确定ScrollBar不需要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 NoneNone

适用于

另请参阅