UIElement.Visibility Property

July 28, 2014

Gets or sets the visibility of a UIElement. A UIElement that is not visible does not render and does not communicate its desired size to layout.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Visibility Visibility { get; set; }
<uiElement Visibility="Visible"/>
-or-
<uiElement Visibility="Collapsed"/>

Property Value

Type: System.Windows.Visibility
A value of the enumeration. The default value is Visibility.Visible.

Dependency property identifier field: VisibilityProperty

Elements where Visibility is not Visible do not participate in input events, are not in a tab sequence (cannot be focused), and are excluded during hit testing.

NoteNote:

The value of IsHitTestVisible is ignored when an object is not set to Visible. IsHitTestVisible is a settable property that enables you to disable hit testing for objects that would otherwise be hit testable by virtue of the Visibility and Background property values.

Windows Phone does not support a Visibilty value of Hidden.

For more information on the XAML syntax, see Visibility.

Visibility in a Visual State

As part of defining visual states for a control, you will sometimes want to change the Visibility state of an object to Collapsed. Visual states rely on animations. The property value type of UIElement.Visibility is Visibility, an enumeration. To animate values that are enumerations, you must use a DiscreteObjectKeyFrame. (You also use this technique for Boolean values).

The following XAML example shows a visual state that uses DiscreteObjectKeyFrame to change visibility.

<VisualState x:Name="Focused">
  <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Visibility" Duration="0">
      <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft