What is the standard convention for defining a subview: display in view mode in MVVM Light

therefore, in classic MVVM examples, you can see that DataTemplate definitions are used to map View Models to Views, what is the standard way to do this in MVVM Light, and where should the mappings be displayed? The following are examples of what I'm doing now and what I'm saying, the mix is ​​important to me.

Main window:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" 
        x:Class="STS2Editor.MainWindow"
        Title="{Binding ApplicationTitle, Mode=OneWay}"
        DataContext="{Binding RootViewModel, Source={StaticResource Locator}}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/ApplicationSkin.xaml" />
                <ResourceDictionary Source="Resources/ViewMappings.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <ContentControl Content="{Binding ApplicationManagementViewModel}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </Grid> 
</Window>

In the above code, my RootViewModel class has an instance of the ApplicationManagementViewModel class with the same property name:

public ApplicationManagementViewModel ApplicationManagementViewModel {get {...} set {...} }

I refer to the ResourceDictionary "ViewMappings.xaml" to indicate how my view model is represented as a view.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:STS2Editor.ViewModel">
    <DataTemplate DataType="{x:Type local:ApplicationManagementViewModel}">
        <local:ApplicationManagementView/>
    </DataTemplate>
</ResourceDictionary>

Should I do similar things with ViewModelLocator? what about collections of view models?

+5
1

, ( DataTemplates), WPF, , , Silverlight. , , .

, DataTemplates , , . , ( , :)

ViewModelLocator MVVM Light, , ( , , WPF/SL). , , ViewModelLocator, -, (., , , ViewModelLocator MEF).

http://www.johnpapa.net/simple-viewmodel-locator-for-mvvm-the-patients-have-left-the-asylum/

, , ViewModelLocator MVVM Light, .

+4

All Articles