title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
---|---|---|---|---|---|---|---|---|---|
How to: Find ControlTemplate-Generated Elements |
Learn how to find ControlTemplate-generated elements, by means of the included code examples in XAML, C#, and Visual Basic. |
03/30/2017 |
|
|
d7b25447-ceff-4bb4-9be5-fd7c40ef00af |
This example shows how to find elements that are generated by a xref:System.Windows.Controls.ControlTemplate.
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]