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 6372763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:16:41+00:00 2026-05-25T01:16:41+00:00

i am having some troubles applying the MVVM pattern, for start i am following

  • 0

i am having some troubles applying the MVVM pattern, for start i am following this example to learn how to apply and use the pattern…

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

So my problem is establishing the “connection” between the View with the ViewModel…

In the example we have a View with a CollectionViewSource where the Source is the AllCustomers property:

<UserControl 
  x:Class="DemoApp.View.AllCustomersView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
    <UserControl.Resources>
        <CollectionViewSource x:Key="CustomerGroups" Source="{Binding Path=AllCustomers}"/>
    </UserControl.Resources>

    <DockPanel>
        <ListView AlternationCount="2" DataContext="{StaticResource CustomerGroups}" ItemsSource="{Binding}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=DisplayName}"/>
                    <GridViewColumn Header="E-mail" DisplayMemberBinding="{Binding Path=Email}"/>
                </GridView>
            </ListView.View>
        </ListView>            
    </DockPanel>
</UserControl>

who belongs to the ViewModel AllCustomersViewModel:

public class AllCustomersViewModel : WorkspaceViewModel
{
    (...)

    public ObservableCollection<CustomerViewModel> AllCustomers { get; private set; }

    (...)
}

but he uses a ResourceDictionary where he applies a DataTemplate between the View and the ViewModel:

<DataTemplate DataType="{x:Type vm:AllCustomersViewModel}">
    <vw:AllCustomersView />
</DataTemplate>

but my problem is because i am not using a ResourceDictionary, and because of that i thought that i can put the DataTemplate in the Resources of the Window where i will have my View (for me is the more logic place to put the DataTemplate)… But for some reason the Data isn’t appearing in the ListView, and so i ask why?

  • 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-25T01:16:42+00:00Added an answer on May 25, 2026 at 1:16 am

    I wouldn’t attach the view model in the Xaml. This hard-codes the Xaml to a specific view model.

    Instead, I’d override the Application startup:

    private void OnStartup(object sender, StartupEventArgs e)
    {
        Views.MainView view = new Views.MainView();
        view.DataContext = new ViewModels.MainViewModel();
        view.Show();
    }
    

    See this article:

    http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx

    This approach is also helpful if you use some sort of tool to dynamically bind your view models in the future, like MEF, Castle.Windsor or Prism.

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

Sidebar

Related Questions

I am having some troubles with my script.. when I access http://www.domain.com/this-is-a-topic I want
I am having some troubles to use iCloud within my mac application. Following what
I am having some troubles understanding the object relationships in Django. I wrote this:
I've having some troubles with the PDO bindValue() function. Whenever I seem to use
I am having some troubles figuring how to use the let form. In the
I'm having some troubles getting my unit tests to be setup to use an
I am having some troubles with DBRef, look this case: db.fruit.save ({_id : 1
I'm having some troubles using Session Variables as they are being used as Reference
I'm building my first ASP.NET MVC application and I am having some troubles with
For some reason I am having troubles with a DBI handle. Basically what happened

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.