UIElement.Visibility UIElement.Visibility UIElement.Visibility UIElement.Visibility Property

定义

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

public:
 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;
    media.Play();
}
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
    media.Play()

End Sub 'PlayMedia

注解

设置此属性将影响的值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.

Visibility 不参与输入事件(或命令)的元素不影响布局的度量值或排列处理方式,不在选项卡序列中,也不会在命中Visible测试中报告。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 NoneNone

适用于

另请参阅