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

定义

获取此元素的呈现宽度。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

属性值

元素的宽度,这是一个采用与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit)的值。The element's width, as a value in 与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit). 默认值为 0(零)。The default value is 0 (zero).

示例

下面的示例显示了各种宽度属性。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

注解

此属性是基于其他宽度输入和布局系统的计算值。This property is a calculated value based on other width inputs, and the layout system. 此值是由布局系统本身基于实际呈现传递设置的, 因此可能会略微滞后于属性的设置值, 例如, 作为Width输入更改的基础。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.

由于ActualWidth是一个计算值, 因此应注意到, 由于布局系统的各种操作, 可能会有多个或增量报告的更改。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. 布局系统可能会计算子元素所需的测量空间、父元素的约束等。The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on.

尽管不能从XAMLXAML设置此属性, 但你可以根据其在样式中的值为Trigger基础。Although you cannot set this property from XAMLXAML, you can base a Trigger upon its value in a style.

依赖项属性信息Dependency Property Information

标识符字段Identifier field ActualWidthProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于