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

  • Home
  • SEARCH
  • 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 4055198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:40:16+00:00 2026-05-20T14:40:16+00:00

I am sure I am missing something simple (still a bit green on this

  • 0

I am sure I am missing something simple (still a bit green on this mvvm stuff), but I thought that the use of ViewModelLocator removed the need of DataTemplate binding view to viewmodel. But for some reason I seem to still need it.

In a WPF application I have a window whose only content is a content template which binds to default binding.

<Window ... DataContext="{Binding MainView, Source={StaticResource Locator}}">
<grid><ContentControl Content="{Binding}"/></grid>

I then have a UserControl which I guess you could say is the real view – viewmodel.

<UserControl ...
DataContext="{Binding MainView, Source={StaticResource Locator}}">
...xaml...
</UserControl>

What I have noticed is that unless I place DataTemplate which binds view – viewmodel (MainView in this case) in App.xaml, I just get the name of the class.

Since the window’s datacontext is bound using the locator, I thought this would work. My guess is that the additional layer in the window using the ContentControl is confusing things.

If I replace the ContentControl with a direct reference to the view, ie.

<view:MainView />

This also works. So I guess I have two questions:
1. Why does the binding not seem to understand this?
2. Is there a way to get this to work using the locator? I would like to have the window with minimal ui, and keep the bulk in UserControls.

Thank you for any information.

Obscured

  • 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-20T14:40:17+00:00Added an answer on May 20, 2026 at 2:40 pm

    each content control can hold any object, if you just assign class without DataTemplate, this is by default translated to string. DataTemplate says how the content should be visualized, including bindings (which propeties of your object should be taken and evaluated).

    ViewModelLocator doesn’t have anything with DataTemplates, it just locates the right view model for you based on name or whatever you want. It is the way how to decouple logic of creating/locating view models and put this at one place.

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

Sidebar

Related Questions

Im sure this will be a simple one but have a project that started
I am not sure if I am missing something grotesquely obvious or what, but
I'm sure I'm missing something pretty simple here. I've created a custom DateTime display
I think I'm missing something simple, but I'm just not seeing it. I have
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
Not sure how to ask a followup on SO, but this is in reference
I'm it really sure how to explain this question but i'll give it a
I'm new to Rails so this is really basic and I'm sure I'm missing
before posting the whole code, i wanted to make sure I am not missing
Not sure if this is possible or if I'm expressing correctly what I'm looking

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.