Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

WPF Team Bloggers

How do I programmatically interact with template-generated elements? Part II

This post shows you how to find a named element within a DataTemplate. In Part I , we discussed how to find a named element within a ControlTemplate. That was fairly simple; you’d call Template.FindName on the control that the ControlTemplate has been applied to. But if the template is a DataTemplate, then the scenario is a bit more complex. For instance, if you have a data-bound ListBox that uses a DataTemplate, each generated list item has a tree of generated elements (as described by your DataTemplate). In this post, we’ll walk through that scenario and retrieve a named element within the DataTemplate of a certain list item. Before showing the code that finds the named element, let’s set up our scenario. We have a Button and a ListBox that’s data-bound (if you want to see how this particular ListBox is bound, you can download the attached zip file). < Border Margin = " 15 " BorderBrush = " Aqua " BorderThickness = " 2 " Padding = " 8 " CornerRadius = " 5 " > < StackPanel > Read More...

Comments

No Comments
Anonymous comments are disabled

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us