UIElement.Arrange(Rect) 메서드

정의

자식 개체의 위치를 지정하고 UIElement의 크기를 결정합니다. 자식 요소에 대한 사용자 지정 레이아웃을 구현하는 부모 개체는 레이아웃 재정의 구현에서 이 메서드를 호출하여 재귀 레이아웃 업데이트를 구성해야 합니다.

public:
 virtual void Arrange(Rect finalRect) = Arrange;
void Arrange(Rect const& finalRect);
public void Arrange(Rect finalRect);
function arrange(finalRect)
Public Sub Arrange (finalRect As Rect)

매개 변수

finalRect
Rect

Rect 값으로 제공되는 레이아웃에서 부모가 자식에 대해 계산하는 최종 크기입니다.

예제

이 예제에서는 ArrangeOverride 구현 내에서 Arrange를 사용하는 방법을 보여줍니다. 레이아웃 구현에 finalRect로 전달하기 전에 원하는 크기를 변경하거나 무시하는 특정 디자인이 없는 한 Arrange를 호출하려는 모든 항목에 대해 DesiredSize를 쿼리해야 합니다.

// Second arrange all children and return final size of panel
protected override Size ArrangeOverride(Size finalSize)
{
    // Get the collection of children
    UIElementCollection mychildren = Children;

    // Get total number of children
    int count = mychildren.Count;

    // Arrange children
    // We're only allowing 9 children in this panel.  More children will get a 0x0 layout slot.
    int i;
    for (i = 0; i < 9; i++)
    {

        // Get (left, top) origin point for the element in the 3x3 block
        Point cellOrigin = GetOrigin(i, 3, new Size(100, 100));

        // Arrange child
        // Get desired height and width. This will not be larger than 100x100 as set in MeasureOverride.
        double dw = mychildren[i].DesiredSize.Width;
        double dh = mychildren[i].DesiredSize.Height;

        mychildren[i].Arrange(new Rect(cellOrigin.X, cellOrigin.Y, dw, dh));

    }

    // Give the remaining children a 0x0 layout slot
    for (i = 9; i < count; i++)
    {
        mychildren[i].Arrange(new Rect(0, 0, 0, 0));
    }


    // Return final size of the panel
    return new Size(300, 300);
}
'Second arrange all children and return final size of panel 
Protected Overrides Function ArrangeOverride(ByVal finalSize As Size) As Size
    'Get the collection of children 
    Dim mychildren As UIElementCollection = Children
    'Get total number of children 
    Dim count As Integer = mychildren.Count
    'Arrange children 
    'only allowing 9 children in this panel. More children will get a 0x0 layout slot. 
    Dim i As Integer
    For i = 0 To 8
        'Get (left, top) origin point for the element in the 3x3 block 
        Dim cellOrigin As Point = GetOrigin(i, 3, New Size(100, 100))
        'Arrange child 
        'Get desired height and width. This will not be larger than 100x100 as set in MeasureOverride. 
        Dim dw As Double = mychildren(i).DesiredSize.Width
        Dim dh As Double = mychildren(i).DesiredSize.Height
        mychildren(i).Arrange(New Rect(cellOrigin.X, cellOrigin.Y, dw, dh))
    Next
    For i = 9 To count - 1
        'Give the remaining children a 0x0 layout slot 
        mychildren(i).Arrange(New Rect(0, 0, 0, 0))
    Next
    'Return final size of the panel 
    Return New Size(300, 300)
End Function
'Calculate point origin of the Block you are in 
Protected Function GetOrigin(ByVal blockNum As Integer, ByVal blocksPerRow As Integer, ByVal itemSize As Size) As Point
    'Get row number (zero-based) 
    Dim row As Integer = CInt(Math.Floor(blockNum / blocksPerRow))
    'Get column number (zero-based) 
    Dim column As Integer = blockNum - blocksPerRow * row
    'Calculate origin 
    Dim origin As New Point(itemSize.Width * column, itemSize.Height * row)
    Return origin
End Function

설명

Arrange 호출은 해당 특정 클래스의 ArrangeOverride 구현에 도달할 수 있습니다. 그렇지 않으면 대부분의 FrameworkElement 클래스에는 Arrange에 대한 암시적 기본 레이아웃 동작이 있습니다.

XAML UI의 초기 레이아웃 위치 계산은 측정값 호출과 정렬 호출로 구성됩니다. 측정값 호출 중에 레이아웃 시스템은 availableSize 측정값을 사용하여 요소의 크기 요구 사항을 결정합니다. 정렬 호출 중에 레이아웃 시스템은 요소 경계 상자의 크기와 위치를 마무리합니다.

레이아웃이 처음 생성되면 정렬 전에 발생하는 측정값 호출이 항상 있습니다. 그러나 첫 번째 레이아웃이 통과한 후에는 앞에 측정값 이 없으면 Arrange 호출이 발생할 수 있습니다. 이는 정렬에만 영향을 주는 속성(예: 맞춤)이 변경되거나 부모가 측정값 없이 Arrange를 받을 때 발생할 수 있습니다.

Measure 호출은 정렬 정보를 자동으로 무효화합니다. 레이아웃 업데이트는 일반적으로 비동기적으로 발생합니다(레이아웃 시스템에 의해 결정되는 시간에). 요소 크기 조정(예: Width)에 영향을 주는 속성의 변경 내용을 요소에 즉시 반영하지 않을 수 있습니다.

UpdateLayout 메서드를 사용하여 기본 제공 레이아웃 시스템 동작에 의존하지 않고 앱 코드에서 레이아웃 업데이트를 강제 적용할 수 있습니다. 그러나 권장되지는 않습니다. 일반적으로 불필요하며 과도하게 사용하면 성능이 저하될 수 있습니다. 속성 변경으로 인해 앱 코드에서 UpdateLayout 을 호출하는 것이 적절할 수 있는 많은 상황에서 레이아웃 시스템은 이미 업데이트를 처리하고 있을 것입니다. 레이아웃 시스템에는 부모-자식 관계를 통해 연속된 레이아웃 변경 내용을 처리하기 위한 최적화가 있으며 UpdateLayout 호출은 이러한 최적화에 대해 작동할 수 있습니다. 그럼에도 불구하고 업데이트레이아웃 을 호출하는 것이 타이밍 문제 또는 다른 레이아웃 문제를 해결하는 가장 좋은 옵션인 더 복잡한 시나리오에서 레이아웃 상황이 존재할 수 있습니다. 의도적으로 그리고 드물게 사용하세요.

적용 대상

추가 정보