views:

170

answers:

1

Hi All,

Situation:

I have a user control which i am adding to an expander. I have a constructor which takes some params. I also have a default constructor which just calls InitializeComponent. I call the constructor with the params to setup the user control. The user control is then added to the expander. The expander is not expanded at this point. When i go to expand the expander the default constructor is called and i lose all the settings previously passed into it.

Next i removed the constructor with the params and setup the user control via public properties, but still the default constructor is called wiping all the settings when the expender is expanded.

Can anyone tell me why, and how to get round this?

Thanks Jason

A: 

Sounds like the Expander creates and deletes the ContentPresenter to save memory. The solution is to not set up the user control at all in code and use data binding to bind to your data - this way it can create and delete all it wants, and the bindings will fix everything up

Paul Betts
I do have data binding on the ctrls which work fine, the image and label on the user control have a valid image and text. the problem is there are other public members variables though which i need to get and set data on. The information these members variables hold is lost.
Jay
Bind the public member variables to your Window, and set those - trying to set the public member variables directly is an antipattern
Paul Betts