FrameworkElement.ActualWidth FrameworkElement.ActualWidth FrameworkElement.ActualWidth FrameworkElement.ActualWidth Property

Definición

Obtiene el ancho representado de este elemento.Gets the rendered width of this element.

public:
 property double ActualWidth { double get(); };
public double ActualWidth { get; }
member this.ActualWidth : double
Public ReadOnly Property ActualWidth As Double

Valor de propiedad

Ancho del elemento, como un valor en unidades independientes de dispositivo (1/96 de pulgada por unidad)device-independent units (1/96th inch per unit).The element's width, as a value in unidades independientes de dispositivo (1/96 de pulgada por unidad)device-independent units (1/96th inch per unit). El valor predeterminado es 0 (cero).The default value is 0 (zero).

Ejemplos

En el ejemplo siguiente se muestran varias propiedades de ancho.The following example displays various width properties.

private void changeWidth(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.Width = sz1;
    rect1.UpdateLayout();
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
    txt2.Text = "Width is set to " + rect1.Width;
    txt3.Text = "MinWidth is set to " + rect1.MinWidth;
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
}
private void changeMinWidth(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.MinWidth = sz1;
    rect1.UpdateLayout();
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
    txt2.Text = "Width is set to " + rect1.Width;
    txt3.Text = "MinWidth is set to " + rect1.MinWidth;
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
}
private void changeMaxWidth(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.MaxWidth = sz1;
    rect1.UpdateLayout();
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
    txt2.Text = "Width is set to " + rect1.Width;
    txt3.Text = "MinWidth is set to " + rect1.MinWidth;
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
}
Private Sub changeWidth(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)
    Dim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
    Dim sz1 As Double = Double.Parse(li.Content.ToString())
    rect1.Width = sz1
    rect1.UpdateLayout()
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth.ToString
    txt2.Text = "Width is set to " + rect1.Width.ToString
    txt3.Text = "MinWidth is set to " + rect1.MinWidth.ToString
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth.ToString
End Sub
Private Sub changeMinWidth(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)

    Dim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
    Dim sz1 As Double = Double.Parse(li.Content.ToString())
    rect1.MinWidth = sz1
    rect1.UpdateLayout()
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth.ToString
    txt2.Text = "Width is set to " + rect1.Width.ToString
    txt3.Text = "MinWidth is set to " + rect1.MinWidth.ToString
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth.ToString
End Sub
Private Sub changeMaxWidth(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)

    Dim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
    Dim sz1 As Double = Double.Parse(li.Content.ToString())
    rect1.MaxWidth = sz1
    rect1.UpdateLayout()
    txt1.Text = "ActualWidth is set to " + rect1.ActualWidth.ToString
    txt2.Text = "Width is set to " + rect1.Width.ToString
    txt3.Text = "MinWidth is set to " + rect1.MinWidth.ToString
    txt4.Text = "MaxWidth is set to " + rect1.MaxWidth.ToString
End Sub

Comentarios

Esta propiedad es un valor calculado basado en otras entradas de ancho y en el sistema de diseño.This property is a calculated value based on other width inputs, and the layout system. El propio sistema de diseño establece el valor en función de un paso de representación real y, por tanto, se puede retrasar ligeramente detrás del valor establecido Width de propiedades como que son la base del cambio de entrada.The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Width that are the basis of the input change.

Dado ActualWidth que es un valor calculado, debe tener en cuenta que puede haber varios cambios o informes incrementales en él como resultado de varias operaciones realizadas por el sistema de diseño.Because ActualWidth is a calculated value, you should be aware that there could be multiple or incremental reported changes to it as a result of various operations by the layout system. El sistema de diseño puede calcular el espacio de medida necesario para los elementos secundarios, las restricciones impuestas por el elemento primario y así sucesivamente.The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on.

Aunque no se puede establecer esta propiedad XAMLXAMLdesde, puede basar Trigger un valor en un estilo.Although you cannot set this property from XAMLXAML, you can base a Trigger upon its value in a style.

Información sobre propiedades de dependenciaDependency Property Information

Campo de identificadorIdentifier field ActualWidthProperty
Propiedades de metadatos establecidas entrueMetadata properties set to true NingunaNone

Se aplica a