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.Visible]。Prior 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 重新定義此屬性的預設值為 CollapsedWhen 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
設定為 true 的中繼資料屬性Metadata properties set to true None