I am making my first WPF application, so this question may seem rather odd. I have been reading about MVVM and so far it has made sense to me. What I don’t understand, though, is separating all the XAML.
What I mean is this: I assume you don’t place everything in the MainWindow.xaml and just collapse controls based upon what is going to be used. I would think you would want a container that would contain xaml of other files. Is this correct?
How do you go about separating the XAML out so that it isn’t just a mash of everything in one file?
There are many ways, including creating a seperate
UserControl,CustomControl,PageorWindowFor example, if you wanted to pull some
XAMLout of yourMainWindow.xaml, you could create aUserControl(right-click project, Add, New Item…, User Control (WPF)) calledMyUserControl.xamllike this:and then use this control in your
MainWindow.xamllike this:Note that you need to add a reference to the namespace of your
UserControl