FrameworkElement.ActualHeight Proprietà

Definizione

Ottiene l'altezza di rendering di un FrameworkElement. Vedere la sezione Osservazioni.

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

Valore della proprietà

Double

double

Altezza, in pixel, dell'oggetto . Il valore predefinito è 0. Il valore predefinito potrebbe essere rilevato se l'oggetto non è stato caricato e non è ancora stato coinvolto in un passaggio di layout che esegue il rendering dell'interfaccia utente.

Esempio

In questo esempio viene illustrato uno scenario comune in cui si usa ActualHeight di uno o più elementi nell'interfaccia utente per impostare l'altezza di uno degli elementi coinvolti o un elemento diverso, in modo che la stessa altezza di rete venga mantenuta dopo l'azione. Questa operazione viene in genere eseguita in risposta ai gestori eventi richiamati quando gli elementi vengono aperti o chiusi oppure l'area di visualizzazione 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();
    }
}

Commenti

Nota

Sebbene abbia un campo di backup ActualHeightProperty, ActualHeight non genera notifiche di modifica delle proprietà e deve essere considerato come una normale proprietà CLR e non una proprietà di dipendenza.

ActualHeight è una proprietà calcolata. I calcoli sono un risultato di un passaggio di layout, in cui l'oggetto viene ridimensionato in base alla logica dei relativi genitori di layout successivi. Per altre informazioni, vedere Definire i layout con XAML.

ActualHeight può avere più modifiche segnalate incrementali al valore a causa delle operazioni del sistema di layout. Se si ottiene il valore durante l'iterazione del layout, il sistema di layout potrebbe comunque calcolare la misura necessaria dello spazio per gli oggetti figlio, i vincoli dell'oggetto padre e così via. Poiché il valore si basa su un passaggio di rendering effettivo, può essere leggermente indietro al valore impostato di proprietà come Height, che può essere la base della modifica di input.

Ai fini dell'associazione ElementName , ActualHeight non pubblica gli aggiornamenti quando cambia (a causa della sua natura calcolata asincrona e di run-time). Non tentare di usare ActualHeight come origine di associazione per un'associazione ElementName . Se si ha uno scenario che richiede aggiornamenti in base a ActualHeight, usare un gestore SizeChanged .

Si applica a

Vedi anche