FrameworkElement.ActualHeight Properti

Definisi

Mendapatkan tinggi FrameworkElement yang dirender. Lihat Keterangan.

public:
 property double ActualHeight { double get(); };
double ActualHeight();
public double ActualHeight { get; }
var double = frameworkElement.actualHeight;
Public ReadOnly Property ActualHeight As Double

Nilai Properti

Double

double

Tinggi, dalam piksel, dari objek . Defaultnya adalah 0. Default mungkin ditemukan jika objek belum dimuat dan belum terlibat dalam kode tata letak yang merender UI.

Contoh

Contoh ini menunjukkan skenario umum di mana Anda menggunakan ActualHeight dari satu atau beberapa elemen di UI untuk mengatur Tinggi salah satu elemen yang terlibat atau elemen yang berbeda, sehingga tinggi bersih yang sama dipertahankan setelah tindakan. Ini biasanya dilakukan sebagai respons terhadap penanganan aktivitas yang dipanggil ketika elemen dibuka atau ditutup, atau area tampilan berubah.

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

Keterangan

Catatan

Meskipun memiliki bidang dukungan ActualHeightProperty , ActualHeight tidak menaikkan pemberitahuan perubahan properti dan harus dianggap sebagai properti biasa dan bukan properti dependensi.

ActualHeight adalah properti terhitung. Perhitungan adalah hasil dari tata letak lulus, di mana objek berukuran dalam tata letak sesuai dengan logika induk tata letak berturut-turut. Untuk informasi selengkapnya lihat Menentukan tata letak dengan XAML.

ActualHeight dapat memiliki beberapa atau perubahan yang dilaporkan bertahap pada nilai karena operasi oleh sistem tata letak. Jika Anda mendapatkan nilai saat tata letak masih iterasi, sistem tata letak mungkin masih menghitung ukuran ruang yang diperlukan untuk objek anak, batasan oleh objek induk, dan sebagainya. Karena nilai didasarkan pada lulus penyajian aktual, nilai mungkin sedikit tertinggal di belakang nilai properti yang ditetapkan seperti Tinggi, yang dapat menjadi dasar dari perubahan input.

Untuk tujuan pengikatan ElementName , ActualHeight tidak memposting pembaruan saat berubah (karena sifat penghitungan asinkron dan run-timenya). Jangan mencoba menggunakan ActualHeight sebagai sumber pengikatan untuk pengikatan ElementName . Jika Anda memiliki skenario yang memerlukan pembaruan berdasarkan ActualHeight, gunakan handler SizeChanged .

Berlaku untuk

Lihat juga

  • ActualWidth
  • Height
  • <xref:Windows.UI.Xaml.FrameworkElement.SizeChanged%0a(frameworkelement_sizechanged.md)>