0

I am coming from programming with WinForms and now start to change into WPF. In WinForms I could easily bind a DataGrid before Runtime, to adjust the columns without coding everything.

The WPF-Datagrid has the property "ItemsSource", but I don't understand how to bind it in editor. I have already a DataSource which refers to a SQL-Database, but it will not be shown in the property window.

How to do this?

Screenshot

  • You bind it through XAML, ``, and why does your DataGrid has a name?! There is no need for those in WPF. – XAMlMAX Jul 26 '19 at 08:56
  • I think I am to stupid for this. That was so easy in WinForms. Just drag & drop the dataSource to the Form and it was done! – Patrick Rainer Jul 26 '19 at 11:06
  • Don't say that!! You just need to learn how to do it in` WPF`, WinForms was free for all, with` WPF` you would use `MVVM` pattern to stop people from doing everything they want, like they did in WinForms. Which makes it more testable, clearer code, allows separation of concerns etc etc... – XAMlMAX Jul 26 '19 at 11:13

1 Answers1

0
  1. you have to expose your collection as a public property
  2. make it visible in the xaml (namespace include)
  3. set up your DataContext correctly
  4. create the binding in XAML and set up the columns, like here

If you want to see the changes in your collection online, you have to use ObservableCollection<>

G. B.
  • 528
  • 2
  • 15
  • Did you look at the screenshot? Should the dataSource not viewable in this ItemSource.DataSource ? – Patrick Rainer Jul 26 '19 at 07:22
  • I had a look at it, but I have never used the GUI to configure the data source. Maybe if you configure it in XAML, it will be visible there. – G. B. Jul 29 '19 at 10:22