1
votes

I am making a wpf application. I am very new to WPF. I have a main layout screen which has a background content and other screens that have the layout plus some more controls exclusive to those screens.

I am doing it as:

The main layout screen is a Window and the other dedicated screens are user controls.

For every specialized screen, I am doing this:

Application.Current.MainWindow mw;
mw.Content = nameOfCurrentUserControl;

Is this idea fine?

1
to counter that question : ask yourself this : does it suit your needs? the downside of this, is that implicit databinding probably won't work, and explicit databinding will have to be done from C# code, rather than XAML. - Timothy Groote
I thought on similar lines but I don't have a clear picture, being new to WPF. Could you please give an example of explicit data binding? or any link that could help. - Ujjwal Vaish
Implicit data binding comes from setting the datacontext of an element. The child elements will then be implicitly databound. you can change this by explicitly setting the datacontext. it would look like this : nameOfCurrentUserControl.DataContext = myDataObject (you could go much further in depth, but i think that is beyond the scope of the question - Timothy Groote

1 Answers

1
votes

If I understand correctly you want to have a program with different pages. Like a wizard for instalation.

Then what you want to do is to create a Window (as you did) and inside it add a Frame. Then you create Pages and in each page you create the layout you want.

Then in your main Window, you create instances of your Pages (mySecondPage = new SecondPage()) and then you Navigate from one page to the other loading them into the frame of the main Window using MyFrame.Navigate(mySecondPage)

Here you have much more information about navigation : http://paulstovell.com/blog/wpf-navigation