FrameworkElement.ActualWidth プロパティ

定義

この要素のレンダリングされた幅を取得します。

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

プロパティ値

デバイスに依存しない単位 (単位あたり 1/96 インチ) の値としての要素の幅。 既定値は 0 (ゼロ) です。

次の例では、さまざまな幅プロパティを表示します。

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

注釈

このプロパティは、他の幅入力とレイアウト システムに基づいて計算される値です。 この値は、実際のレンダリング パスに基づいてレイアウト システム自体によって設定されるため、入力変更の基礎となる Width などのプロパティの設定値よりもわずかに遅れる可能性があります。

ActualWidthは計算値であるため、レイアウト システムによるさまざまな操作の結果として、複数または増分の変更が報告される可能性があることに注意してください。 レイアウト システムでは、子要素の必要なメジャー領域、親要素による制約などを計算できます。

XAML からこのプロパティを設定することはできませんが、スタイル内の値に基づいて Trigger を設定できます。

依存関係プロパティ情報

品目 価値
識別子フィールド ActualWidthProperty
に設定されたメタデータ プロパティ true None

適用対象