Reputation: 3799
Basically I have a DataTemplate that contains Border, StackPanel and stuff, and later I use this DataTemplate as a ContentTemplate in many ContentControl(s).
These ContentControl(s) are named, but from the C# code I don't manage to find a way to get back my Border, StackPanel and stuff from them.
Any ideas?
Upvotes: 0
Views: 469
Reputation: 537
You should be able to do somthing like this:
// Finding textBlock from the DataTemplate that is set on that ContentPresenter
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
TextBlock myTextBlock = (TextBlock)myDataTemplate.FindName("textBlock", myContentPresenter);
And you can find more about it here: How to: Find DataTemplate-Generated Elements
Upvotes: 1