Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-create-and-use-a-gridlengthconverter-object.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

1.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Create and Use a GridLengthConverter Object 03/30/2017
csharp
vb
Grid control [WPF], creating [WPF], GridLengthConverter objects
5ab75911-e36a-4825-80e4-081c57e8e182

How to: Create and Use a GridLengthConverter Object

Example

The following example shows how to create and use an instance of xref:System.Windows.GridLengthConverter. The example defines a custom method called changeCol, which passes the xref:System.Windows.Controls.ListBoxItem to a xref:System.Windows.GridLengthConverter that converts the xref:System.Windows.Controls.ContentControl.Content%2A of a xref:System.Windows.Controls.ListBoxItem to an instance of xref:System.Windows.GridLength. The converted value is then passed back as the value of the xref:System.Windows.Controls.ColumnDefinition.Width%2A property of the xref:System.Windows.Controls.ColumnDefinition element.

The example also defines a second custom method, called changeColVal. This custom method converts the xref:System.Windows.Controls.Primitives.RangeBase.Value%2A of a xref:System.Windows.Controls.Slider to a xref:System.String and then passes that value back to the xref:System.Windows.Controls.ColumnDefinition as the xref:System.Windows.Controls.ColumnDefinition.Width%2A of the element.

Note that a separate [!INCLUDETLA#tla_xaml] file defines the contents of a xref:System.Windows.Controls.ListBoxItem.

[!code-csharpgridlengthConverterGrid#1] [!code-vbgridlengthConverterGrid#1]

See also