UIElement.Visibility 屬性

定義

取得或設定這個項目的 使用者介面 (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; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
member this.Visibility : System.Windows.Visibility with get, set
Public Property Visibility As Visibility

屬性值

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

備註

設定這個屬性會影響的值 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 會將這個屬性的預設值重新定義為 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 也會將預設值重新定義為 CollapsedPopup 且其衍生類別會有類似的產生行為。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

適用於

另請參閱