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重新定義預設值,這個屬性是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
若要設定的中繼資料屬性 trueMetadata properties set to true None

適用於

另請參閱