BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Presentation Foundation
.NET 4.0+

WPF Base Classes - UIElement - Visibility and Status

The twenty-second part of the Windows Presentation Foundation Fundamentals tutorial looks further at the UIElement type, which is a base class of WPF layout controls, as well as other WPF controls. This article describes visibility and status properties.

IsEnabled Property

The final property that we'll look at in this article is IsEnabled. This holds a Boolean value. When true, the control might be enabled and allow interaction such as mouse clicks, keyboard events and receiving the focus. When set to false, this interactivity is disabled and the control may be rendered differently to show its disabled status. When you disable a control that has children, the child controls are also disabled, even if their IsEnabled flags are set to true.

For the last demonstration, modify the XAML for the "IsEnabled" button:

<Button Margin="3" Click="IsEnabled_Click">IsEnabled</Button>

Now add the following code so that the button toggles the IsEnabled status for the StackPanel:

private void IsEnabled_Click(object sender, RoutedEventArgs e)
{
    LeftPanel.IsEnabled = !LeftPanel.IsEnabled;
}

Run the program and click the "IsEnabled" button to see the effect. Whilst disabled, the StackPanel's rendering is unaffected. The labels and button are greyed out to show that they will not respond to input. Also, clicking the "Click Me!" button does not show the message when its parent StackPanel is disabled.

Disabled Left Panel

25 July 2013