Question

I have a silverlight user control which is "bound" to a Document object. the document class contains an array of Field objects. The intention is that when the control is bound to a document, each field in the document is bound to a control in the user control. Each field has a name and the control in the user control that is to be bound to that field is given the same name (so if the field is called "FirstName" there will be a text box in the user control with x:Name="FirstName"). In order to determine which control is to be bound to which field i used the following code:

private void BindDocumentToUserControl(Document document)
{
    foreach (Field field in document.Fields)
    {
        Control c = this.FindName(field.Name);

        if (c != null)
        {
            //bind control to field...
        }
    }
}

this all works fine until i try to put the controls into a tab control. when the user control is first loads (and the user has not changed the selected tab themselves) then the above method finds all of the controls. however, if the user changes the selected tab and then re-binds the control, this.FindName will only find the controls that are in the selected tab. if i pass the name of a control in a different tab that i know is correct it will still return null.

i found the article below regarding the same issue however the solution is not really apporiate for what i'm trying to do. any help would be greatly appreciated

http://forums.silverlight.net/forums/p/59912/248977.aspx

Was it helpful?

Solution

As a bit of a hack of an answer, couldn't you load the controls for each tab to a hidden panel, one tab at a time, then once the controls are loaded, move them back into the tab?

I can't say this definitely works, but it sounds "logical", if a bit of a dirty hack....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top