0
votes

I'm using MVVM pattern to develop a WPF application. I want to display dynamic columns to DataGrid from Datatable.

I have added code to display it but it is not working. Datatable is filled with data but In datagrid , data is not displaying.

XAML:

 <DataGrid Grid.Row="1" AutoGenerateColumns="False" GridLinesVisibility="All" Foreground="Black" ItemsSource="{Binding ItemSource, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" />

ViewModel:

private DataView _itemSource;

public DataView ItemSource
{
    get { return _itemSource; }
    set
    {
        _itemSource = value;
        OnPropertyChanged("ItemSource");
    }
}

public async Task PopulateData(string queryText)
{
    var dt = await CustomReportQueryDAO.GetCustomReportQueryResult("select * from [Person]");
    ItemSource = dt.DefaultView;
}         
1

1 Answers

1
votes

You have set AutoGenerateColumns="False" on the DataGrid and you have not defined any columns.

Try changing to AutoGenerateColumns="True"