Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-find-controltemplate-generated-elements.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.7 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Find ControlTemplate-Generated Elements 03/30/2017
csharp
vb
ControlTemplates [WPF], finding elements
finding ControlTemplate elements [WPF]
d7b25447-ceff-4bb4-9be5-fd7c40ef00af

How to: Find ControlTemplate-Generated Elements

This example shows how to find elements that are generated by a xref:System.Windows.Controls.ControlTemplate.

Example

The following example shows a style that creates a simple xref:System.Windows.Controls.ControlTemplate for the xref:System.Windows.Controls.Button class:

[!code-xamlFindGeneratedItems#CT]

To find an element within the template after the template has been applied, you can call the xref:System.Windows.FrameworkTemplate.FindName%2A method of the xref:System.Windows.Controls.Control.Template%2A. The following example creates a message box that shows the actual width value of the xref:System.Windows.Controls.Grid within the control template:

[!code-csharpFindGeneratedItems#CTFindElement] [!code-vbFindGeneratedItems#CTFindElement]

See also