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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:14:16+00:00 2026-06-18T09:14:16+00:00

I am writing a WPF program using C# and targeting .Net 4.0. I am

  • 0

I am writing a WPF program using C# and targeting .Net 4.0. I am trying to follow the MVVM pattern, where my view (code-behind) has minimal-to-no code.

I have a List<MyRecord> that I want to display in the GUI using a DataGrid. In my XAML, I have the following:

<DataGrid x:Name="RecordGrid" ...>
   <DataGrid.Columns>
      <DataGridTextColumn Binding="{Binding RecId}" Header="Record ID"/>
      <DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
   </DataGrid.Columns>
</DataGrid>

All that’s left is to bind this grid to a data collection.

When I bind it in the code-behind file, it works fine:

RecordGrid.ItemsSource = MyRecordList;

However, I would prefer to bind it declaratively in XAML. So I tried this:

<DataGrid x:Name="RecordGrid" ItemsSource="{Binding MyRecordList}" ...>

but it silently doesn’t work. There is no XAML binding error message when the datagrid loads. I set a breakpoint on MyRecordList’s get method, and it’s never invoked as long as ItemsSource is defined declaratively.

How can I get my datagrid to pull from MyRecordList via XAML?

  • 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-18T09:14:17+00:00Added an answer on June 18, 2026 at 9:14 am

    You need to set the DataContext if you want the binding to work…
    The MVVM pattern has a View and a ViewModel. The View is your UI – e.g. the Window (Let’s call it MainWindow) and your ViewModel is where you have the RecordGrid property and all theother commands/properties (let’s call the class MainWindowViewModel)

    You need to connect them both, This is done by specifying in your View, who the DataContext is (in our case the MainWindowViewModel class).

    So you’ll want to do something like this in your View’s constructor:

        public MainWindow()
        {
            this.DataContext = new MainWindowViewModel();
            InitializeComponent();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a WPF application with C# as the code behind and I want
I'm writing a WPF application and trying to bind an image to my view
I am just writing my first program using WPF and C#. My windows just
Im writing a wpf project and using the MVVM paradigm, what i was wondering
I am writing some data visualization code in WPF with MVVM Light. Here's a
When writing a WPF application using MVVM, I want to use a WCF service,
I am using Moq, NUnit, WPF, MVVM, Ninject. I am writing a test for
I am writing WPF application using MVVM. I have ObservableCollection of my items: public
A WPF program I'm writing in C# has the following interface on the back-end:
I'm writing a WPF application while mostly adhering to the MVVM design pattern. The

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.