FrameworkElement.ActualHeight Propiedad

Definición

Obtiene el alto representado de un frameworkElement. Vea la sección Comentarios.

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

Valor de propiedad

Double

double

La altura, en píxeles del objeto . El valor predeterminado es 0. Es posible que se encuentre el valor predeterminado si el objeto no se ha cargado y aún no ha participado en un pase de diseño que representa la interfaz de usuario.

Ejemplos

En este ejemplo se muestra un escenario común en el que se usa ActualHeight de uno o varios elementos de la interfaz de usuario para establecer el alto de uno de los elementos implicados o un elemento diferente, de modo que el mismo alto neto se mantenga después de la acción. Esto suele hacerse en respuesta a los controladores de eventos que se invocan cuando los elementos se abren o cierran, o el área de presentación cambia.

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

Comentarios

Nota

Aunque tiene un campo de respaldo ActualHeightProperty , ActualHeight no genera notificaciones de cambio de propiedad y debe considerarse como una propiedad normal y no una propiedad de dependencia.

ActualHeight es una propiedad calculada. Los cálculos son el resultado de un paso de diseño, donde el objeto tiene el tamaño en el diseño según la lógica de sus elementos primarios de diseño sucesivos. Para obtener más información, consulta Definir diseños con XAML.

ActualHeight puede tener varios cambios notificados o incrementales en el valor debido a las operaciones del sistema de diseño. Si obtiene el valor mientras el diseño sigue iterando, es posible que el sistema de diseño siga calculando la medida de espacio necesaria para los objetos secundarios, las restricciones del objeto primario, etc. Dado que el valor se basa en un paso de representación real, puede retardo ligeramente detrás del valor establecido de propiedades como Height, que puede ser la base del cambio de entrada.

Para los fines del enlace ElementName , ActualHeight no publica actualizaciones cuando cambia (debido a su naturaleza calculada asincrónica y en tiempo de ejecución). No intente usar ActualHeight como origen de enlace para un enlace ElementName . Si tiene un escenario que requiere actualizaciones basadas en ActualHeight, use un controlador SizeChanged .

Se aplica a

Consulte también

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