Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-position-the-child-elements-of-a-grid.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.1 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date dev_langs helpviewer_keywords ms.assetid
How to: Position the Child Elements of a Grid Learn how to use the get and set methods that are defined on a Windows Presentation Foundation Grid to position child elements. 03/30/2017
csharp
vb
Grid control [WPF], positioning child elements
27b3ba9b-ad32-44e2-bcab-a79d573a463c

How to: Position the Child Elements of a Grid

This example shows how to use the get and set methods that are defined on xref:System.Windows.Controls.Grid to position child elements.

Example

The following example defines a parent xref:System.Windows.Controls.Grid element (grid1) that has three columns and three rows. A child xref:System.Windows.Shapes.Rectangle element (rect1) is added to the xref:System.Windows.Controls.Grid in column position zero, row position zero. xref:System.Windows.Controls.Button elements represent methods that can be called to reposition the xref:System.Windows.Shapes.Rectangle element within the xref:System.Windows.Controls.Grid. When a user clicks a button, the related method is activated.

[!code-xamlgridGetSetMethods]

The following code-behind example handles the methods that the button xref:System.Windows.Controls.Primitives.ButtonBase.Click events raise. The example writes these method calls to xref:System.Windows.Controls.TextBlock elements that use related get methods to output the new property values as strings.

[!code-csharpgridGetSetMethods#2] [!code-vbgridGetSetMethods#2]
Here is the finished result!

a screenshot depicts a WPF user interface with two columns, the right side has a 3 x 3 grid and the left has buttons to move a colored rectangle between the columns and rows of the grid

See also