Reputation: 412
this is the constructor of the UserControl which includes DataGrid Element.
public Results(List<CartItem> Items)
{
InitializeComponent();
this.Items.DataContext = Items;
}
and this is the XAML of the DataGrid.
<DataGrid AutoGenerateColumns="False" Name="Items" IsReadOnly="True" MinHeight="300">
<DataGrid.Columns>
<DataGridCheckBoxColumn>
<DataGridCheckBoxColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource styleCheckBox}" IsChecked="{Binding IsSelected}"/>
</DataTemplate>
</DataGridCheckBoxColumn.HeaderTemplate>
</DataGridCheckBoxColumn>
<DataGridTextColumn Header="Abone No" Binding="{Binding SubscriberNo}" />
<DataGridTextColumn Header="Adı Soyadı" Binding="{Binding SubscriberName}" />
<DataGridTextColumn Header="Fatura Tutarı" Binding="{Binding _Amount, Mode=OneWay}" />
<DataGridTextColumn Header="Son Ödeme Tarihi" Binding="{Binding _Deadline, Mode=OneWay}" />
</DataGrid.Columns>
</DataGrid>
I double checked for DataContext object of the DataGrid is properly populated. But No data being shown in DataGrid. What am I doing wrong?
Upvotes: 1
Views: 412
Reputation: 791
You only have set the DataContext of your Grid. You also have to set the ItemsSource of your Datagrid like this:
<DataGrid ItemsSource="{Binding}"
Upvotes: 2