title: MVVM, ViewModelLocator, dynamically show View with ViewModel based on property
body: <p><img src="https://i.stack.imgur.com/lDu0W.jpg" alt="enter image description here">I have a design question. Please look at the attached image to get an idea of the app design.
  Basicaly I just need help in finding the correct approach here.</p>
  
  <p>I have a View and ViewModel that holds an TileUserControl.
  It takes a collection of tiles, and displays them in the defined size, color, order and so one. It is also capable of grouping the tales in groups, and allowing the user to add and remove Tiles.</p>
  
  <p>The Tile object look like this.</p>
  
  <pre><code>    public class Tile
      {
          public int ID { get; set; }
          public string View { get; set; }
          public List&lt;string&gt; Views { get; set; }
          public string TileSize { get; set; }
  
      }
  </code></pre>
  
  <p>So far all good. Everything works fine.</p>
  
  <p>All tiles have content. I want to set the content to the View and the ViewModel corresponding to the View string on the Tile Object.</p>
  
  <p>I am using MVVM Light, but may also use Caliburn Mico.
  The tiles Control is DevExpress TileLayoutControl for WPF.</p>
  
  <p><a href="http://documentation.devexpress.com/#WPF/clsDevExpressXpfLayoutControlTileLayoutControltopic" rel="nofollow noreferrer">DevExpress TileLayoutControl doc</a></p>
  
  <p>EDIT: Updated With MainTilesView XAML</p>
  
  <pre><code>    &lt;Grid&gt;
  
          &lt;dxlc:TileLayoutControl Padding="60,41,0,0"
                                  ItemsSource="{Binding Tiles}" 
                                  ScrollBars="None" 
                                  ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                                  AllowGroupHeaderEditing="False" 
                                  AllowMaximizedElementMoving="True" Background="{x:Null}"&gt;
  
              &lt;dxlc:TileLayoutControl.GroupHeaderStyle&gt;
                  &lt;Style TargetType="dxlc:TileGroupHeader"&gt;
                      &lt;Setter Property="Foreground" Value="White"/&gt;
                      &lt;Setter Property="FontSize" Value="24"/&gt;
                      &lt;Setter Property="FontFamily" Value="Segeo UI"/&gt;
                      &lt;Setter Property="FontWeight" Value="Light"/&gt;
                  &lt;/Style&gt;
              &lt;/dxlc:TileLayoutControl.GroupHeaderStyle&gt;
  
              &lt;dxlc:TileLayoutControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;dxlc:Tile Header="{Binding Header}" 
                                 Size="{Binding TileSize}" 
                                 dxlc:TileLayoutControl.GroupHeader="{Binding GroupHeader}" 
                                 Tag="{Binding ID}"  
                                 dxlc:FlowLayoutControl.IsFlowBreak="{Binding IsNewGroup}" 
                                 Background="{Binding BackgroundColor}"&gt;
                      &lt;/dxlc:Tile&gt;
                  &lt;/DataTemplate&gt;
              &lt;/dxlc:TileLayoutControl.ItemTemplate&gt;
  
              &lt;dxlc:TileLayoutControl.Resources&gt;
                  &lt;conv:IsUserControlConverter x:Key="IsUserControlConverter"/&gt;
                  &lt;conv:StringToTileConverter x:Key="StringToTileConverter"/&gt;
                  &lt;Style TargetType="{x:Type dxlc:Tile}"&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}" Value="ExtraSmall"&gt;
                              &lt;Setter Property="Size" Value="ExtraSmall"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}" Value="1x1"&gt;
                              &lt;Setter Property="Size" Value="ExtraSmall"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}" Value="1x1"&gt;
                              &lt;Setter Property="Size" Value="Small"/&gt;
                              &lt;Setter Property="Width" Value="150"/&gt;
                              &lt;Setter Property="Height" Value="150"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="1x2"&gt;
                              &lt;Setter Property="Size" Value="Large"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="2x1"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="150"/&gt;
                              &lt;Setter Property="Height" Value="310"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="2x2"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="2x3"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="310"/&gt;
                              &lt;Setter Property="Height" Value="470"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="3x2"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="470"/&gt;
                              &lt;Setter Property="Height" Value="310"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="3x3"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="470"/&gt;
                              &lt;Setter Property="Height" Value="470"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="4x2"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="630"/&gt;
                              &lt;Setter Property="Height" Value="310"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="4x3"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="630"/&gt;
                              &lt;Setter Property="Height" Value="470"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="4x4"&gt;
                              &lt;Setter Property="Size" Value="ExtraLarge"/&gt;
                              &lt;Setter Property="Width" Value="630"/&gt;
                              &lt;Setter Property="Height" Value="630"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Path=TileSize}"  Value="Single_1x1"&gt;
                              &lt;Setter Property="Size" Value="Large"/&gt;
                              &lt;Setter Property="Width" Value="150"/&gt;
                              &lt;Setter Property="Height" Value="150"/&gt;
                          &lt;/DataTrigger&gt;
  
  
  
                          &lt;DataTrigger Binding="{Binding Path=View,Converter={StaticResource IsUserControlConverter}}" Value="true"&gt;
                              &lt;Setter Property="ContentTemplate"&gt;
                                  &lt;Setter.Value&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;ContentControl cal:View.Model="{Binding Path=View, Converter={StaticResource StringToTileConverter}, UpdateSourceTrigger=Explicit}"/&gt;                                        
                                      &lt;/DataTemplate&gt;
                                  &lt;/Setter.Value&gt;
                              &lt;/Setter&gt;
                          &lt;/DataTrigger&gt;
  
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/dxlc:TileLayoutControl.Resources&gt;
  
          &lt;/dxlc:TileLayoutControl&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>My issue is how to get the UserControl from Tile.View loaded into the Tile content.
  I have tride above with DataTrigger and DataTemplate.</p>
  
  <p>The StringToTileConverter just Returns the name of the ViewModel.</p>
  
  <p>Currently using Caliburn Micro, and my binding workes fine outside of the template part, but I can't get them to work with the DataTemplate.</p>
  
  <p>Also all this code is not very clean, so therefor I ask if anyone have a more clean way to do it.</p>