FrameworkElement.ActualHeight 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 FrameworkElement的呈現高度。 請參閱<備註>。
public:
property double ActualHeight { double get(); };
double ActualHeight();
public double ActualHeight { get; }
var double = frameworkElement.actualHeight;
Public ReadOnly Property ActualHeight As Double
屬性值
double
物件的高度,以圖元為單位。 預設值是 0。 如果物件尚未載入且尚未參與轉譯 UI 的設定階段,可能會發生預設值。
範例
此範例顯示常見的案例,其中您在 UI 中使用一或多個元素的 ActualHeight 來設定其中一個涉及元素或不同元素的高度,以便在動作之後維護相同的淨高度。 這通常是為了回應在開啟或關閉專案或顯示區域變更時叫用的事件處理常式。
void SDKSample::WebViewControl::PageWithAppBar::BottomAppBar_Opened(Object^ sender, Object^ obj)
{
// AppBar has Opened so we need to put the WebView back to its
// original size/location.
AppBar^ bottomAppBar = (AppBar^) sender;
if (bottomAppBar != nullptr)
{
// Force layout so that we can guarantee that our AppBar's
// actual height has height
this->UpdateLayout();
// Get the height of the AppBar
double appBarHeight = bottomAppBar->ActualHeight;
// Reduce the height of the WebView to allow for the AppBar
WebView8->Height = WebView8->ActualHeight - appBarHeight;
// Translate the WebView in the Y direction to reclaim the space occupied by the AppBar.
TranslateYOpen->To = -appBarHeight / 2.0;
// Run our translate animation to match the AppBar
OpenAppBar->Begin();
}
}
void BottomAppBar_Opened(object sender, object e)
{
// AppBar has Opened so we need to put the WebView back to its
// original size/location.
AppBar bottomAppBar = sender as AppBar;
if (bottomAppBar != null)
{
// Force layout so that we can guarantee that our AppBar's
// actual height has height
this.UpdateLayout();
// Get the height of the AppBar
double appBarHeight = bottomAppBar.ActualHeight;
// Reduce the height of the WebView to allow for the AppBar
WebView8.Height = WebView8.ActualHeight - appBarHeight;
// Translate the WebView in the Y direction to reclaim the space occupied by
// the AppBar. Notice that we translate it by appBarHeight / 2.0.
// This is because the WebView has VerticalAlignment and HorizontalAlignment
// of 'Stretch' and when we reduce its size it reduces its overall size
// from top and bottom by half the amount.
TranslateYOpen.To = -appBarHeight / 2.0;
// Run our translate animation to match the AppBar
OpenAppBar.Begin();
}
}
Private Sub BottomAppBar_Opened(sender As Object, e As Object)
' AppBar has Opened so we need to put the WebView back to its
' original size/location.
Dim bottomAppBar As AppBar = TryCast(sender, AppBar)
If bottomAppBar IsNot Nothing Then
' Force layout so that we can guarantee that our AppBar's
' actual height has height
Me.UpdateLayout()
' Get the height of the AppBar
Dim appBarHeight As Double = bottomAppBar.ActualHeight
' Reduce the height of the WebView to allow for the AppBar
WebView8.Height = WebView8.ActualHeight - appBarHeight
' Translate the WebView in the Y direction to reclaim the space occupied by
' the AppBar. Notice that we translate it by appBarHeight / 2.0.
' This is because the WebView has VerticalAlignment and HorizontalAlignment
' of 'Stretch' and when we reduce its size it reduces its overall size
' from top and bottom by half the amount.
TranslateYOpen.[To] = -appBarHeight / 2.0
' Run our translate animation to match the AppBar
OpenAppBar.Begin()
End If
End Sub
備註
注意
雖然它具有 ActualHeightProperty 支援欄位,但 ActualHeight 不會引發屬性變更通知,而且應該視為一般屬性,而不是相依性屬性。
ActualHeight 是匯出屬性。 計算是版面設定階段的結果,其中物件會根據其後續版面配置父系的邏輯來調整大小。 如需詳細資訊,請參閱 使用 XAML 定義版面配置。
ActualHeight 可能會因為版面配置系統的作業而對值進行多個或累加報告變更。 如果您在配置仍在逐一查看時取得值,版面配置系統可能仍會計算子物件所需的空間量值、父物件的條件約束等等。 因為值是以實際轉譯階段為基礎,所以可能會稍微落後 一些屬性的設定值,例如 Height,這可能是輸入變更的基礎。
基於 ElementName 系結的目的,ActualHeight 不會在因非同步和執行時間計算本質) 而變更 (時張貼更新。 請勿嘗試使用 ActualHeight 做為 ElementName 系結的系結來源。 如果您有需要以 ActualHeight 為基礎的更新案例,請使用 SizeChanged 處理常式。
適用於
另請參閱
- ActualWidth
- Height
- <xref:Windows.UI.Xaml.FrameworkElement.SizeChanged%0a(frameworkelement_sizechanged.md)>