FrameworkElement.ActualHeight Свойство

Определение

Возвращает отрисованную высоту объекта FrameworkElement. См. заметки.

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

Значение свойства

Double

double

Высота объекта (в пикселях). Значение по умолчанию равно 0. Значение по умолчанию может возникнуть, если объект не был загружен и еще не участвовал в проходе макета, который отображает пользовательский интерфейс.

Примеры

В этом примере показан распространенный сценарий, в котором используется 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)>