I'm trying to learn MVVM. I decided to create a test project right away with the right structure. For starters, I have a Views folder. In it, I separately described the main window (MVVMSample.Views.MainWindow) and the main view as usercontrol (MVVMSample.Views.MainView). Then I, like in some example found on the Internet, write the following in App.xaml.cs:

using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; using MVVMSample.Views; namespace MVVMSample { public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { var window = new MainWindow(); var view = new MainView(); window.Content = view; window.Show(); } } } 

And in App.xaml left only:

 <Application x:Class="MVVMSample.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/> 

Here I have not yet created a Model or ViewModel, only View so that at least you can run the application. But the problem is, I don’t see MainView in the window at all. Those. so that I do not throw in MainView (buttons, content everyone ...) I have an empty window. What's the matter???

Closed due to the fact that the participants are off topic: Athari , aleksandr barakin , Grundy , Pavel Mayorov , PashaPash 20 Apr '16 at 9:24 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Athari, aleksandr barakin, Grundy, Pavel Mayorov, PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • do not think, specify the user control in the xaml of the main window, and not window.Content = view; - vitidev
  • @vitidev it is called not wisely, but to strictly follow the pattern, even when it brings a few more additional code. - PECHAPTER
  • The MVVM pattern does not require what you specify. Moreover, the essence of the MVVM pattern is that you control the DataContext, and what the view itself already draws is drawn. So your string is window.Content = view; This is your personal wish, and not following the pattern. - vitidev
  • @vitidev was just like that in the example I found. And how do you suggest then to set the ViewModel for the View? For the same, you must first get somewhere the object of the View itself, and if it is specified in the xaml-markup, I don’t even know ... - THE PECH REPAIR
  • one
    Set the view model to the window in which this view and it will automatically receive it. - vitidev

0