Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:31:04+00:00 2026-05-14T08:31:04+00:00

so in classic MVVM examples ive seen DataTemplate definitions are used to map up

  • 0

so in classic MVVM examples ive seen DataTemplate definitions are used to map up View Models to Views, what is the standard way to do this in MVVM Light framework, and where should the mappings be located? Following are examples of what I’m doing now and what I’m talking about, blendability 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 class ApplicationManagementViewModel with the same property name:

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

I reference the ResourceDictionary “ViewMappings.xaml” to specify 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 be doing things like this using ViewModelLocator? what about collections of view models?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:31:04+00:00Added an answer on May 14, 2026 at 8:31 am

    The method you use (with implicitly typed DataTemplates) works OK in WPF, but unfortunately it does not work in Silverlight. This is one of the reason why I prefer to use a more explicit method which works in both worlds.

    Also, implicitly typed DataTemplates can be a bit confusing, because it is not always quite clear where the template comes from. That can render the work of the integrator very difficult at times, especially for small changes to the UI (been there, done that 🙂

    There is no obligation to use the ViewModelLocator in MVVM Light, it is just a way that works well and is quite easy to understand (for people reading the code who are not familiar with the subtleties of WPF/SL). In the end, it is very much a matter of preference, but lately the ViewModelLocator pattern seems to gain in popularity (see for example this post where a generic ViewModelLocator is used together with MEF).

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

    Finally, let me add that I am not very satisfied with the current implementation of the ViewModelLocator in MVVM Light, and I want to propose a much more generic solution in the next version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In classic ASP, you can dump a recordset into an array using getRows(). This
I have a classic parent-collection of children relationship that is being used in a
The classic Fisher Yates looks something like this: void shuffle1(std::vector<int>& vec) { int n
In classic MVC the model notifies the view about changes made on it. In
Apologies if this is classic ASP 101, but its been so long since I
Classic ASP, VBScript context. A lot of articles including this Microsoft one , say
The classic of writing a singleton in java is like this: public class SingletonObject
In classic Asp we used the File.Type property to get the friendly name associated
In classic ASP.NET Web Forms view engine, we can set the ContentType in the
I have this classic ASP site which has been working fine until we updated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.