mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +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
31 lines
1.7 KiB
Markdown
31 lines
1.7 KiB
Markdown
---
|
|
title: "How to: Find ControlTemplate-Generated Elements"
|
|
ms.date: "03/30/2017"
|
|
dev_langs:
|
|
- "csharp"
|
|
- "vb"
|
|
helpviewer_keywords:
|
|
- "ControlTemplates [WPF], finding elements"
|
|
- "finding ControlTemplate elements [WPF]"
|
|
ms.assetid: 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-xaml[FindGeneratedItems#CT](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml#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-csharp[FindGeneratedItems#CTFindElement](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml.cs#ctfindelement)]
|
|
[!code-vb[FindGeneratedItems#CTFindElement](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FindGeneratedItems/VisualBasic/Window1.xaml.vb#ctfindelement)]
|
|
|
|
## See also
|
|
|
|
- [Find DataTemplate-Generated Elements](../data/how-to-find-datatemplate-generated-elements.md)
|
|
- [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview)
|
|
- [WPF XAML Namescopes](../advanced/wpf-xaml-namescopes.md)
|
|
- [Trees in WPF](../advanced/trees-in-wpf.md)
|