0
Ansis
5y

Hey guys, any WPF developers here?

I'm having lotsa trouble getting WPF XAML data bindings to work. Disclaimer - I'm new to OOP and thhe syntax of OOP is so damn confusing I'm never sure anything is the "right" way.

The task is to create test data for certain classes and output it in WPF. The code I have is a public static class that generates test data for certain classes and stores these objects inside a static List<Object> depending on the object. I couldn't figure out any other way to store all these objects to later be able to output them.

Then I found out that you can use ObservableCollection to automate a lot of the CRUD stuff. So I tried to change the Lists to static ObservableCollections. It mostly works and I even got it to output the data in XAML by using DataGrid.ItemsSource = TestDataCreationClass.authors in the MainWindow.xaml.cs. However, I can not for the life of me figure out how to do the bind through XAML only using the ItemsSource property. No matter what I do, it cannot find the Collection.

I googled for quite a while and every example seems completely different from mine so I'm at a loss.

If you need any more info or code snippets I'd be glad to provide them.

Any kind of help is appreciated.
Thanks in advance!

Comments
  • 0
    Are you using x:Static? Is your DataContext property of your view set such that your binding path will work (it should be TestDataCreationClass if you want your binding path to be "authors" judging by your comment)? While usually only mildly helpful, what did the binding error say in the debug output ?
Add Comment