Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Error while assigning observer collection to list box

$
0
0

Im having list box and I want to add to it items and when I tried with the following code I got error

Object reference not set to an instance of an object."

the error is when I do item source = _userList ,

what am I doing wrong here?

        public ObservableCollection<User> _UsersList = new ObservableCollection<User>();

        public MainWindow()
        {
            _UsersList.Add(new User {Name = "Mike"});
            _UsersList.Add(new User { Name = "Nick" });
     listbox1.ItemsSource = _UsersList;
            DataContext = this;
            InitializeComponent();



          


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>