FrameworkElement.ActualHeight Propriedade

Definição

Obtém a altura renderizada de um FrameworkElement. Consulte Observações.

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

Valor da propriedade

Double

double

A altura, em pixels, do objeto . O padrão é 0. O padrão poderá ser encontrado se o objeto não tiver sido carregado e ainda não estiver envolvido em uma passagem de layout que renderize a interface do usuário.

Exemplos

Este exemplo mostra um cenário comum em que você usa o ActualHeight de um ou mais elementos na interface do usuário para definir a Altura de um dos elementos envolvidos ou um elemento diferente, de modo que a mesma altura líquida seja mantida após a ação. Isso geralmente é feito em resposta a manipuladores de eventos que são invocados quando os elementos são abertos ou fechados, ou a área de exibição é alterada.

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

Comentários

Observação

Embora tenha um campo de suporte ActualHeightProperty , ActualHeight não gera notificações de alteração de propriedade e deve ser considerado como uma propriedade regular e não uma propriedade de dependência.

ActualHeight é uma propriedade calculada. Os cálculos são resultado de uma passagem de layout, em que o objeto é dimensionado no layout de acordo com a lógica de seus pais de layout sucessivos. Para obter mais informações, consulte Definir layouts com XAML.

ActualHeight pode ter várias alterações relatadas ou incrementais no valor devido a operações do sistema de layout. Se você receber o valor enquanto o layout ainda estiver iterando, o sistema de layout ainda poderá estar calculando a medida necessária de espaço para objetos filho, restrições pelo objeto pai e assim por diante. Como o valor é baseado em uma passagem de renderização real, ele pode ficar um pouco atrás do valor definido de propriedades como Height, que pode ser a base da alteração de entrada.

Para fins de associação ElementName , ActualHeight não publica atualizações quando é alterado (devido à sua natureza calculada assíncrona e em tempo de execução). Não tente usar ActualHeight como uma origem de associação para uma associação ElementName . Se você tiver um cenário que exija atualizações com base em ActualHeight, use um manipulador SizeChanged .

Aplica-se a

Confira também

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