FrameworkElement.ArrangeOverride(Size) 메서드

정의

레이아웃의 "정렬" 패스에 대한 동작을 제공합니다. 클래스는 이 메서드를 재정의하여 고유한 "Arrange" 패스 동작을 정의할 수 있습니다.

protected:
 virtual Size ArrangeOverride(Size finalSize) = ArrangeOverride;
Size ArrangeOverride(Size const& finalSize);
protected virtual Size ArrangeOverride(Size finalSize);
function arrangeOverride(finalSize)
Protected Overridable Function ArrangeOverride (finalSize As Size) As Size

매개 변수

finalSize
Size

이 개체가 자신과 자식을 정렬하는 데 사용해야 하는 부모 내의 마지막 영역입니다.

반환

요소가 레이아웃으로 정렬된 후 사용되는 실제 크기입니다.

예제

이 예제에서는 ArrangeOverride를 구현하여 사용자 지정 패널 구현에 대한 "Arrange" 전달 논리를 사용자 지정합니다. 특히 코드의 이러한 측면은 다음과 같습니다.

  • 자식을 반복합니다.
  • 각 자식에 대해 HeightWidthDesiredSize를 기반으로 하는 Rect를 사용하여 Arrange를 호출하고 XY는 패널과 관련된 논리를 기반으로 합니다.
  • 크기를 반환합니다(이 경우 이 간단한 패널은 정렬된 Rect 값 측정값을 누적할 때 계산된 크기가 아닌 고정 크기를 반환합니다).
// 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

설명

이 메서드에는 대부분의 FrameworkElement 파생 클래스에 대한 기본 제공 레이아웃을 수행하는 기본 구현이 있습니다. ArrangeOverride는 다른 클래스에 대해 고유한 ArrangeOverride 메서드를 포함하여 내부 레이아웃 논리 또는 자체 앱의 코드에 의해 Arrange 가 호출될 때마다 Arrange에 대한 동작을 제공합니다. 템플릿 지정 컨트롤을 생성하는 경우 ArrangeOverride 논리는 컨트롤의 특정 "정렬" 패스 레이아웃 논리를 정의합니다.

앱이 실행되면 요소가 레이아웃 프로세스를 통과하는 방법에 대한 일반적인 디자인은 "측정값" 패스와 "정렬" 패스의 두 단계로 나뉩니다. 레이아웃 처리의 "정렬" 패스를 사용자 지정하려는 컨트롤 작성자(또는 패널 작성자)는 ArrangeOverride를 재정의해야 합니다. 구현 패턴은 표시되는 각 자식 개체에서 Arrange 를 호출하고 각 자식 개체에 대해 원하는 최종 크기를 finalRect 매개 변수로 전달해야 합니다. Arrange가 호출되지 않으면 자식 개체가 렌더링되지 않습니다.

봉인되지 않은 몇몇 기존 클래스는 이 메서드의 재정의 구현을 제공합니다. 눈에 띄는 항목으로는 StackPanelGrid가 있습니다. 일반적으로 ArrangeOverride의 동작은 레이아웃 컨테이너 자체에 배치되는 사용자 정의 값을 위반하지 않는 finalSize 를 생성합니다. 예를 들어 finalSize 는 일반적으로 컨테이너의 높이너비보다 크지 않으며 콘텐츠 영역에 영향을 주는 Margin 또는 Padding 값을 차지합니다. 특히 컨테이너 크기를 초과하는 시나리오가 있는 컨트롤은 더 큰 값을 반환할 수 있지만 해당 컨트롤을 사용하는 모든 사용자는 컨테이너 크기로 인해 발생하는 클리핑 및 위치 지정 문제를 고려해야 합니다. ArrangeOverride 구현이 각 자식 개체에 대해 Arrange에 전달하는 값은 일반적으로 이전 Measure 호출에 의해 DesiredSize에 설정된 값입니다.

적용 대상

추가 정보