MVVM DataContext for Link

May 16, 2013 at 7:03 AM
Edited May 16, 2013 at 7:27 AM
Hi,

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:ModernTab.Links>
                        <mui:Link DisplayName="Clues" Source="/Lovatts.ClueExplorer.Views;component/CluesView.xaml"></mui:Link>
                        <mui:Link DisplayName="Suggestions" Source="/Lovatts.ClueExplorer.Views;component/ClueSuggestionsView.xaml" />
                    </mui:ModernTab.Links>
                </mui:ModernTab>
            </Grid>
Now... normally I'd have a ResourceDictionary full of DataTemplates saying things like
    <DataTemplate DataType="{x:Type ViewModels:CluesViewModel}">
        <Views:CluesView></Views:CluesView>
    </DataTemplate>

    <DataTemplate DataType="{x:Type ViewModels:ClueSuggestionViewModel}">
        <Views:ClueSuggestionView></Views:ClueSuggestionView>
    </DataTemplate>
And simply Bind the Content of a ContentPresenter to the appropriate instance ViewModel, eg.
            <TabControl>
                <TabItem Header="Clues">
                    <ContentPresenter Content="{Binding CluesViewModel}"></ContentPresenter>
                </TabItem>
                <TabItem Header="Suggestions">
                    <ContentPresenter Content="{Binding ClueSuggestionsViewModel}"></ContentPresenter>                    
                </TabItem>
            </TabControl>
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 5:42 AM
Edited May 24, 2013 at 5: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 :)