Permalink
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (32 sloc) 1.88 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Create a Custom Panel Element
03/30/2017
.net-framework
dotnet-wpf
article
Panel control
custom Panel elements
e0df4f1e-8c07-4e86-89a3-e22acfffdc2a
9
dotnet-bot
dotnetcontent
wpickett

How to: Create a Custom Panel Element

Example

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

The example defines a simple custom xref:System.Windows.Controls.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 xref:System.Windows.Controls.Panel behaviors, the example uses the xref:System.Windows.FrameworkElement.MeasureOverride%2A and xref:System.Windows.FrameworkElement.ArrangeOverride%2A methods. Each method returns the xref:System.Windows.Size data that is necessary to position and render child elements.

[!code-cppPlotPanel#1] [!code-csharpPlotPanel#1] [!code-vbPlotPanel#1]

See Also

xref:System.Windows.Controls.Panel
Panels Overview
Create a Custom Content-Wrapping Panel Sample