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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:14:56+00:00 2026-06-14T03:14:56+00:00

Hi im learning about MVVM and Win8 app development, and Im having trouble with

  • 0

Hi im learning about MVVM and Win8 app development, and Im having trouble with binding an ObservableCollection (located in NoteViewModel.cs) to my MainPage listbox (or listview) through XAML.

public ObservableCollection<Note> NotesList;

The Model is a simple Note.cs class, which holds NoteText, Priority and RemindDate.

What Im doing right now is set the DataContext in the code-behind file of MainPage.xaml.cs
to the ObservableCollection.

public MainPage()
{
    this.InitializeComponent();
    NoteViewModel nvm = new NoteViewModel();
    noteListView.DataContext = nvm.NotesList;
}

And in the NoteViewModel Constructor I simply create 2 new Notes which I then add to the Collection.

What I would like to do is set the DataContext in XAML to the NoteViewModel and the ItemsSource to the NotesList. I want to implement a DetailsView to a single note later.

There are lots of tutorial with binding collections to listboxes,
but I havent found one which shows the MVVM-correct way to do so.

Any help?

  • 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-06-14T03:14:57+00:00Added an answer on June 14, 2026 at 3:14 am

    You need to bind your View (MainPage) to your ViewModel, rather than setting the DataContext of your list to the collection

    Then in your view’s xaml, you bind the list’s ItemSource to your ViewModels NotesList property

    E.G.

    ViewModel:

    public NoteViewModel : INotifyPropertyChanged
    {
      //Collection must be a property
      public ObservableCollection<Note> NotesList {get; private set;}
    
      public NoteViewModel()
      {
         //Initialize your collection in the constructor
         NotesList = new ObservableCollection<Note>()
      }
    
      //.
      //.
      //.
    
    }
    

    You can still set the DataContext in code behind if you wish

    public MainPage()
    {
      this.InitializeComponent();
      NoteViewModel nvm = new NoteViewModel();
      this.DataContext = nvm;
    }
    

    Alternatively you can set the DataContext via your View’s xaml. Assuming your ViewModel is in the namespace MyProject:

    Add a reference to your namespace

    <UserControl x:class=MyProject.MainPage
      xmlns:local="clr-namespace:MyProject"
      .
      .
    >
    

    Add the ViewModel as a resource

    <UserControl.Resources>
      <local:NoteViewModel x:Key="NoteViewModel"/>
    </UserControl.Resources>
    

    Bind your main container’s DataContext to this resource

    <Grid x:Name="LayoutRoot" DataContext="{StaticResource NoteViewModel}">
    

    After you have set the DataContext, you then need to set the ItemSource for the notesListView control via a binding

    ItemSource={Binding NotesList}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning about pointers and arrays in class. My trouble is in the
I'm learning about using Caliburn.Micro as a MVVM framework for a WPF application. In
I'm learning about MVVM and one of the things I don't get is how
I am learning about MVVM so I can support an application that my predecessor
I'm just learning about MVVM in WPF, I'm completely new both to WPF as
I'm learning about Android development, and I read that if you want to create
Learning about notifyAll made me question something about notify: in a typical situation we
After learning about the Action delegate in C# I've been looking for ways I
I am learning about raw sockets. I heard that ping utility is using raw
I'm learning about C++11 concurrency, where my only prior experience with concurrency primitives was

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.