This is a migrated thread and some comments may be shown as answers.

Controls inside a user control are null, why?? Any workaround?

1 Answer 54 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pinho
Top achievements
Rank 1
Pinho asked on 24 Mar 2009, 11:16 AM
Hi,

 we developed a sort of wizard control that allows user to create an object with the information collect during the wizard "life".

 It's a standard Silverlight user control, with a grid as a container. The developer just have to define the pages and the objects that go within those pages.

 Now, we are facing a big problem, when we try to access the objects, they're always null :(

 We improved the FindByName to overcome this (based on the example of the VisualTreeWalker), we get the object on run-time by name, we create a "proxy" in development time, and work with these proxies instead of working with the controls directly.

 This is a major pain, we have pages with 20 controls and we have to create 20 temporary objects. Just to get the text defined in a text box we have to:

Create a proxy like: TextBox textBoxNameInternal;
Then get the instance:  textBoxNameInternal = VisualTreeWalker.FindName<TextBox>("textBoxName", gridPage);
Only then we can do: textBoxNameInternal.Text;

Imagine this multiplied by several wizards, by several controls on each wizard page and you can imagine how this can delay the development. :(

Did any of you have ever faced a similar problem? Did you manage to overcome this?

Thanks,

L. Pinho

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Mar 2009, 11:31 AM
Hi Luis,

I'm not sure about VisualTreeWalker however I've attached small example demonstrating how to use our own extension methods.

Let me know what you think.

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Pinho
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or