UIElement.Visibility 属性


获取或设置此元素的 用户界面 (UI)user interface (UI) 可见性。Gets or sets the 用户界面 (UI)user interface (UI) visibility of this element. 这是依赖项属性。This is a dependency property.

 property System::Windows::Visibility Visibility { System::Windows::Visibility get(); void set(System::Windows::Visibility value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public System.Windows.Visibility Visibility { get; set; }
member this.Visibility : System.Windows.Visibility with get, set
Public Property Visibility As Visibility


枚举的一个值。A value of the enumeration. 默认值为 VisibleThe default value is Visible.



下面的示例实现了一个处理程序,该处理程序引用了两个不同的命名按钮,它们分别是用户界面中的互斥对。The following example implements a handler that references two different named buttons that are intended to be a mutually exclusive pair in the user interface. 在运行与按钮关联的实际程序逻辑之前,按钮本身设置为 "Visibility.Hidden",并将该对中的另一个按钮设置为 Visibility.VisiblePrior to running the actual program logic associated with the button, the button itself is set to be Visibility.Hidden, and the other button in the pair is set to Visibility.Visible.

private void PlayMedia(object sender, MouseButtonEventArgs args)
    pauseBTN.Visibility = Visibility.Visible;
    playBTN.Visibility = Visibility.Collapsed;

    media.SpeedRatio = 1.0;
Private Sub PlayMedia(ByVal sender As Object, ByVal args As MouseButtonEventArgs)
    pauseBTN.Visibility = System.Windows.Visibility.Visible
    playBTN.Visibility = System.Windows.Visibility.Collapsed

    media.SpeedRatio = 1.0

End Sub


设置此属性会影响 IsVisible的值,而这又可能引发 IsVisibleChanged 事件。Setting this property affects the value of IsVisible, which in turn may raise the IsVisibleChanged event. IsVisible 具有影响它的其他因素,例如,包含它的父级的可见性设置。However, IsVisible has other factors that influence it, for instance the visibility settings of parents that contain it.

Visible Visibility 的元素不参与输入事件(或命令),不影响布局的度量值或排列处理方式,不在选项卡序列中,也不会在命中测试中报告。Elements where Visibility is not Visible do not participate in input events (or commands), do not influence either the Measure or Arrange passes of layout, are not in a tab sequence, and will not be reported in hit testing.

当由 Window 或其派生类继承时,Window 将此属性的默认值重定义为 "Collapsed"。When inherited by Window or its derived classes, Window redefines the default value of this property to be Collapsed. 这会影响未对最初创建的 Window运行布局测量处理过程,并且 RenderSize 返回(0,0)。This has the effect of not running the Measure pass of layout on an initially created Window, and RenderSize returns (0,0). 有关详细信息,请参阅 WindowFor details, see Window. Popup 还会重新定义要 Collapsed的默认值,Popup 及其派生类产生类似的结果行为。Popup also redefines the default value to be Collapsed, with similar resulting behavior for Popup and its derived classes.

依赖项属性信息Dependency Property Information

标识符字段Identifier field VisibilityProperty
元数据属性设置为 trueMetadata properties set to true None