Search code examples
wpfmvvmviewmodelmvvmcross

MVVMCross using Frame to have multiple Views on the same View - Biding dosen't work


I'm trying to get a MVVMCross WPF application to run in a particular way, having multiple Views in the same "big view". Seems that Cross is not really made to be used like this, but let's try it anyways. So what I've done so far is using to add two Views into the same container "MainView".

A MainView with two other Views added as frames: https://i.sstatic.net/kSXVA.png

<Frame Grid.Row="0" Grid.Column="0" Source="XMLFileView.xaml" Margin="5"/>
<Frame Grid.Row="0" Grid.Column="1" Source="BinaryFileView.xaml" Margin="5" />

This ugly thing is a MainView with two Views inside frames. The Views do work properly by themselves but when added through a Frame the "MVVM binding magic" is lost and View<->ModelView lose their connection.

How can I manually add multiple ModelViews to my MainView? Or perhaps there's a better way to have multiple Views displayed together, suggestions?


Solution

  • Is XMLFileView.xaml an user control? If yes, u can just use directly the user control and set the DataContext, e.g.

    <controls:XMLFileView DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext}" />
    

    more information

    If not, then it's better to use DataTemplate according to here