MVVM DataContext for Link

May 16, 2013 at 8:03 AM
Edited May 16, 2013 at 8:27 AM

This project looks absolutely amazing! I am however, clueless as to how to DataTemplate a ViewModel and have it in a Link :/

So I have something like this for example...
 <Grid Grid.Column="1" Style="{StaticResource ContentRoot}">
                <mui:ModernTab  SelectedSource="/Lovatts.ClueExplorer.Views;component/CluesView.xaml" Layout="Tab">
                        <mui:Link DisplayName="Clues" Source="/Lovatts.ClueExplorer.Views;component/CluesView.xaml"></mui:Link>
                        <mui:Link DisplayName="Suggestions" Source="/Lovatts.ClueExplorer.Views;component/ClueSuggestionsView.xaml" />
Now... normally I'd have a ResourceDictionary full of DataTemplates saying things like
    <DataTemplate DataType="{x:Type ViewModels:CluesViewModel}">

    <DataTemplate DataType="{x:Type ViewModels:ClueSuggestionViewModel}">
And simply Bind the Content of a ContentPresenter to the appropriate instance ViewModel, eg.
                <TabItem Header="Clues">
                    <ContentPresenter Content="{Binding CluesViewModel}"></ContentPresenter>
                <TabItem Header="Suggestions">
                    <ContentPresenter Content="{Binding ClueSuggestionsViewModel}"></ContentPresenter>                    
In this case, CluesViewModel and ClueSuggestionsViewModel are properties of MainViewModel.

How do I.. er, achieve this in MUI? I'm missing something blindingly obvious aren't I? :/ How do I tell a ModernTab Link what it's DataContext is?

Many thanks, this project looks spectacular!
May 24, 2013 at 6:42 AM
Edited May 24, 2013 at 6:42 AM
The answer it would appear, is to use a View-first MVVM style :) Ie, a View initializes it's ViewModel, instead of a ViewModel being DataTemplated :)