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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:21:25+00:00 2026-05-26T15:21:25+00:00

I am a noob for the WPF. Hope i can find answer. For example,

  • 0

I am a noob for the WPF. Hope i can find answer.

For example,
I have an List<Customer>, and it is binded to dataGrid. If i add a new Customer to the list, and i don’t see the datagrid add a new row there.

<DataGrid ItemsSource="{Binding Customers}" AutoGenerateColumns="False" Height="318">
    <DataGrid.Columns>
        <DataGridTextColumn Header="First Name" Binding="{Binding FirstName, Mode=TwoWay}" />
        <DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Height="80" Source="{Binding Image,Mode=TwoWay}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;

namespace DataGrid
{
    public class MainWindowViewModel
    {
        public ICollectionView Customers { get; private set; }
        public ICollectionView GroupedCustomers { get; private set; }
        public List<Customer> _customers { get; set; }

        public MainWindowViewModel()
        {
            _customers = new List<Customer>
                             {
                                 new Customer
                                     {
                                         FirstName = "Christian",
                                         LastName = "Moser",
                                         Gender = Gender.Male,
                                         WebSite = new Uri("http://www.wpftutorial.net"),
                                         ReceiveNewsletter = true,
                                         Image = "Images/christian.jpg"
                                     },
                                 new Customer
                                     {
                                         FirstName = "Peter",
                                         LastName = "Meyer",
                                         Gender = Gender.Male,
                                         WebSite = new Uri("http://www.petermeyer.com"),
                                         Image = "Images/peter.jpg"
                                     },
                                 new Customer
                                     {
                                         FirstName = "Lisa",
                                         LastName = "Simpson",
                                         Gender = Gender.Female,
                                         WebSite = new Uri("http://www.thesimpsons.com"),
                                         Image = "Images/lisa.jpg"
                                     },
                                 new Customer
                                     {
                                         FirstName = "Betty",
                                         LastName = "Bossy",
                                         Gender = Gender.Female,
                                         WebSite = new Uri("http://www.bettybossy.ch"),
                                         Image = "Images/betty.jpg"
                                     }
                             };
            Customers = CollectionViewSource.GetDefaultView(_customers);
            GroupedCustomers = new ListCollectionView(_customers);
            GroupedCustomers.GroupDescriptions.Add(new PropertyGroupDescription("Gender"));         
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;

namespace DataGrid
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private new MainWindowViewModel view { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            view = new MainWindowViewModel();
            DataContext = view;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            view._customers.Add(new Customer
                                {
                                    FirstName = "Lei",
                                    LastName = "Moser",
                                    Gender = Gender.Male,
                                    WebSite = new Uri("http://www.wpftutorial.net"),
                                    ReceiveNewsletter = true,
                                    Image = "Images/christian.jpg"
                                });
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace DataGrid
{    
    public enum Gender
    {
        Male, 
        Female
    }

    public class Customer : INotifyPropertyChanged
    {
        private string _firstName;
        private string _lastName;
        private Gender _gender;
        private Uri _webSite;
        private bool _newsletter;
        private string _image;

        public string FirstName
        {
            get { return _firstName; }
            set 
            {
                _firstName = value;
                NotifyPropertyChanged("FirstName");
            }
        }

        public string LastName
        {
            get { return _lastName; }
            set
            {
                _lastName = value;
                NotifyPropertyChanged("LastName");
            }
        }

        public Gender Gender
        {
            get { return _gender; }
            set
            {
                _gender = value;
                NotifyPropertyChanged("Gender");
            }
        }

        public Uri WebSite
        {
            get { return _webSite; }
            set
            {
                _webSite = value;
                NotifyPropertyChanged("WebSite");
            }
        }

        public bool ReceiveNewsletter
        {
            get { return _newsletter; }
            set
            {
                _newsletter = value;
                NotifyPropertyChanged("Newsletter");
            }
        }

        public string Image
        {
            get { return _image; }
            set
            {
                _image = value;
                NotifyPropertyChanged("Image");
            }
        }

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region Private Helpers
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}

I set the bindingMode to TwoWay and I have a button_onClick and just add a new customers to the binded list, but the thing i don’t see Datagrid add a new row for it.
Can anyone 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-05-26T15:21:26+00:00Added an answer on May 26, 2026 at 3:21 pm

    The problem is that List<T> does not implement INotifyCollectionChanged. Without that, nothing tells WPF that a new item has been added.

    The best option here is to change your class to use ObservableCollection<T> instead of List<T>. This will cause WPF to automatically be notified whenever items are added or removed from the collection, and it will update appropriately.

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

Sidebar

Related Questions

I'm a noob when it comes to WPF; In win forms I can do
I am a WPF noob and i hope to stop being so one day
Near total WPF noob. So I hooked up a combobox to have checkboxes using
i am new to WPF so maybe this will be noob question but i
Noob question, apologies. I'm compiling Java in Windows Vista's command-line and have so many
Noob question. I have this situation where I have these objects: class Address {
Noob question. :) I'm trying to add Margin to a Header through out my
Total noob question here, but not finding the answer via search. What is the
A noob here. I have a personal Macbook and I want to use Git
A noob question, I'm afraid. I have a database with several classes, among them

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.