信息
您所需的主题如下所示。但此主题未包含在此库中。

FrameworkElement.ArrangeOverride 方法

When overridden in a derived class, positions child elements and determines a size for a FrameworkElement derived class.

命名空间: System.Windows
程序集: PresentationFramework(在 presentationframework.dll 中)

protected virtual Size ArrangeOverride (
	Size finalSize
)
protected Size ArrangeOverride (
	Size finalSize
)
protected function ArrangeOverride (
	finalSize : Size
) : Size
不能在 XAML 中使用方法。

参数

finalSize

The final area within the parent that this element should use to arrange itself and its children.

返回值

The actual size used.

给继承者的说明: Control authors who want to customize the arrange pass of layout processing should override this method. The implementation pattern should call Arrange on each visible child element, and pass the final desired size for each child element as the finalRect parameter. Parent elements should call Arrange on each child, otherwise the child elements will not be rendered. Many derived classes offer implementations of this method. Prominent ones include: Window.ArrangeOverride, Page.ArrangeOverride and Control.ArrangeOverride.

This example shows how to override the default layout behavior of the Panel element and create custom layout elements that are derived from Panel.

The example defines a simple custom Panel element called PlotPanel, which positions child elements according to two hard-coded x- and y-coordinates. In this example, x and y are both set to 50; therefore, all child elements are positioned at that location on the x and y axes.

To implement custom Panel behaviors, the example uses the MeasureOverride and ArrangeOverride methods. Each method returns the Size data that is necessary to position and render child elements.

public class PlotPanel : Panel
{
    // Default public constructor
    public PlotPanel()
        : base()
    {
    }

    // Override the default Measure method of Panel
    protected override Size MeasureOverride(Size availableSize)
    {
        Size childSize = availableSize;
        foreach (UIElement child in InternalChildren)
        {
            child.Measure(childSize);
        }
        return availableSize;
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        foreach (UIElement child in InternalChildren)
        {
            double x = 50;
            double y = 50;

            child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
        }
        return finalSize; // Returns the final Arranged size
    }
}

For the complete sample, see Create a Simple Custom Panel Behavior Sample.

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework

受以下版本支持:3.0

社区附加资源

显示:
© 2014 Microsoft