Is there a way around a missing FindName method in a Silverlight DataTemplate?

According to the C # compiler and Silverlight 2 documentation, Silverlight does not provide the FindName method for the DataTemplate class. I want to find the border that is inside the ContentPresenter. What is the best way to use SilverLight 2?

+4
source share
2 answers

If the border is inside a DataTemplate and not a ControlTemplate, then the only way I have been able to do this in the past is to use VisualTreeHelper to find the item you want.

+3
source

Not quite sure that I understand the script, but since you mention a DataTemplate, I assume you are using a template.

If you use a template, then what you do gives your border a name (x: Name = "border"), and then overrides the OnApplyTemplate method. In this method, you use GetTemplateChild and pass in the name that you used. This will return a link to your border.

If you are not using a template and have a link to ContentPresenter, then you can write a recursive function that considers the Content property for the child element and if it is not a border, then the same function is called in its contents.

0
source

All Articles