mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-07 16:06:07 +02:00
* 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
32 lines
2.1 KiB
Markdown
32 lines
2.1 KiB
Markdown
---
|
|
title: "How to: Position the Child Elements of a Grid"
|
|
description: Learn how to use the get and set methods that are defined on a Windows Presentation Foundation Grid to position child elements.
|
|
ms.date: "03/30/2017"
|
|
dev_langs:
|
|
- "csharp"
|
|
- "vb"
|
|
helpviewer_keywords:
|
|
- "Grid control [WPF], positioning child elements"
|
|
ms.assetid: 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-xaml[gridGetSetMethods](~/samples/snippets/csharp/VS_Snippets_Wpf/gridGetSetMethods/CSharp/Window1.xaml)]
|
|
|
|
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-csharp[gridGetSetMethods#2](~/samples/snippets/csharp/VS_Snippets_Wpf/gridGetSetMethods/CSharp/Window1.xaml.cs#2)]
|
|
[!code-vb[gridGetSetMethods#2](~/samples/snippets/visualbasic/VS_Snippets_Wpf/gridGetSetMethods/VisualBasic/Window1.xaml.vb#2)]
|
|
Here is the finished result!
|
|
|
|

|
|
|
|
## See also
|
|
|
|
- <xref:System.Windows.Controls.Grid>
|
|
- [Panels Overview](panels-overview.md)
|