It is hard to tell what is happening as you do not provide you data model. Data Binding has requirements that may not be met.
Here is an introduction to the DataGrid:
The DataGrid control - The complete WPF tutorial[
^]. The Second page shows binding controls to the data. Additional information on the control is also included that may be helpful for you.
As for Data Binding, here is a good tutorial:
Introduction to WPF data binding - The complete WPF tutorial[
^]
UPDATE
Following up the question below, here is a simple working example:
1. Data Model =
WidgetModel
public class WidgetModel
{
public string Name { get; set; }
public bool IsChecked { get; set; }
}
2. Simple behind View data initializing and data binding:
public partial class MainWindow : Window
{
public ObservableCollection<WidgetModel> Widgets { get; init; }
public MainWindow()
{
InitializeComponent();
Widgets = new ObservableCollection<WidgetModel>
{
new WidgetModel { Name = "Item 1", IsChecked = true},
new WidgetModel { Name = "Item 2"}
};
DataContext = this;
}
}
3. Finally the View itself:
<DataGrid ItemsSource="{Binding Widgets}">
</DataGrid>
The only difference between my example and the example in the links provided above is that I set the
DataContext
for the View (Window) and point the
ItemSource
to the collection in the View.
This is a working example. It is also the bare minimum to making it work.
Again, all is provided in the links above. The rest is up to you.