BradStevenson
BradStevenson

Reputation: 1994

Passing objects between user controls in WPF

I have got an application that contains a series of input fields(TextBoxes, ComboBoxes etc.) When a button is clicked the user inputs are initialized into a new custom object. The content of the window is then replaced with a new UserControl (So I now have a blank view to display new information on).

I want to bind some of the method outputs from the object created in the first view, to text boxes in the new User Control which has been displayed.

the new object is created when the button is clicked so isn't initialized at the start.

But the obvious error is that the newObject I made in the first view doesn't exist in the context of the second view

Hope that sort of makes sense

any help appreciated

Upvotes: 0

Views: 989

Answers (1)

akjoshi
akjoshi

Reputation: 15772

Instead of replacing the UserControls you can just Hide/Show them, this way you can access them in your other views.

But this is not a very good design and will be problematic in case a lot of controls are there in your window. Better approch would be to use MVVM and save the output of views in the MVVM properties etc.

Upvotes: 2

Related Questions