Reputation: 1
In any large application I have this problem:
I am building window look and I want it to have for example menu on left, some content in the middle etc.
Now if I want to reuse some of this stuff (most of it) or simply I don't want to keep it all in one xaml file how do I do that? Till now I used to do this like this:
In main Window (xaml) i put:
<DockPanel>
<ContentControl Content="{Binding Menu}" DockPanel.Dock="Left"/>
<ContentControl Content="{Binding MainStuff}"/>
</DockPanel>
In main WindowViewModel i put:
Menu = new MenuViewModel();
MainStuff = new MainStuffViewModel();
And sometimes those VModels have to reffer to MainViewModel but rarely.
This approach is not very good couse I can't see my design in main window xaml editor (sometimes I can see it, I don't know, visual probably tries to do binding before compilation but sometimes it fails, I don't want to think about it :))
What is pro approach here?
Upvotes: 0
Views: 132
Reputation: 1904
Do you have a corresponding MenuView for your MenuViewModel?
In that case you can replace your ContentControl like the following:
<DockPanel>
<prefix:MenuView DataContext="{Binding Menu}" DockPanel.Dock="Left"/>
<prefix:MainStuffView DataContext="{Binding MainStuff}"/>
</DockPanel>
This way you get design view of your MenuView- and MainStuffView-usercontrols
Upvotes: 1