I have a simple AvaloniaUI application following the MVVM pattern.
In my view, I have the following ContentControl
<ContentControl Content="{Binding InputContent}" />
My ViewModel contains the following
private DataGrid inputContent = new();
public DataGrid InputContent
{
get => this.inputContent;
set
{
this.inputContent = value;
OnPropertyChanged(nameof(InputContent));
}
}
// this method is called during app runtime
private DoMagic()
{
DataGrid dataGrid = new();
DataTable dataTable = new("MyData");
dataTable.Columns.Add(new DataColumn("ID", typeof(int)));
dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
dataTable.Rows.Add(1, "Alice");
dataTable.Rows.Add(2, "Bob");
// This one behaves the same as AsDataView(); call
// dataGrid.ItemsSource = dataTable.DefaultView;
dataGrid.ItemsSource = dataTable.AsDataView();
dataGrid.AutoGenerateColumns = true;
this.InputContent = dataGrid;
}
While debugging and using Visualizer on the dataTable.DefaultView
call, I can see the data as expected.
But when the app executes the code and populates the InputContent
with the dataTable.DefaultView
, the DataGrid
looks like this.
After digging and debugging, I noticed that the DataGrid
displays DataRowView
instead of the data itself.
Any idea what this may be caused by? Or how to prevent the app from behaving like this?