Problem Binding array of Processes to WPF ListBox?

I am wondering why you are getting an output at all ItemsSource="{Binding Path=ProcessName} Means the source of items is the ProcessName. The name is a string and a string is an IEnumerableIf you do this the binding of your list would change to ItemsSource="{Binding procList} However you should introduce a property and implement INotifyPropertyChanged so your UI is notified and updated when the datasource changes TL;DR version: taking a look at guides to XAML/Bindings and the MVVM Pattern is required if you want to take use full use of WPF.

I am wondering why you are getting an output at all. ItemsSource="{Binding Path=ProcessName}" Means the source of items is the ProcessName. The name is a string and a string is an IEnumerable.So the listbox displays each char as one entry.

You have to set the ItemsSource to the list itself. In your case it would be ItemsSource="{Binding}" Because the ProcessList is already the data context of your grid, which gets inherited to the listbox. If you are not using a view model class (which is best practice when working with the MVVM pattern) you can do a DataContext = this; in your windows constructor to set the data context of the window to its own code-behind.

If you do this the binding of your list would change to ItemsSource="{Binding procList}" However you should introduce a property and implement INotifyPropertyChanged so your UI is notified and updated when the datasource changes. TL;DR version: taking a look at guides to XAML/Bindings and the MVVM Pattern is required if you want to take use full use of WPF.

Thanks for the reply. I'll look further into the MVVM pattern, have heard of it before but never studied it in detail. When I implement your change and have it as ItemsSource="{Binding}" the list populates but none of the entries have any text, any idea how I'd go about fixing this?

– Gareth Foster Sep 25 at 22:03 2 That is because you should set a DisplayMemberPath="ProcessName" in your ComboBox..... (assuming that ProcessName is the property in that represents name of the process in Process class) – AngelWPF Sep 26 at 7:41.

So the listbox displays each char as one entry. You have to set the ItemsSource to the list itself. Because the ProcessList is already the data context of your grid, which gets inherited to the listbox.

If you are not using a view model class (which is best practice when working with the MVVM pattern) you can do a DataContext = this; in your windows constructor to set the data context of the window to its own code-behind. However you should introduce a property and implement INotifyPropertyChanged so your UI is notified and updated when the datasource changes. TL;DR version: taking a look at guides to XAML/Bindings and the MVVM Pattern is required if you want to take use full use of WPF.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions