I'm upgrading a WPF app to UWP, and I'm stuck with upgrading the DataGrid control. I'm trying to upgrade System.Windows.Controls.DataGrid (the old WPF control) -> Microsoft.Toolkit.Uwp.UI.Controls.DataGrid (the new MS recommended community control)
The old version works fine. It is populating the grid from a .NET DataTable. XAML:
<DataGrid SelectionMode="Single" SelectionChanged="dataGridSongs_SelectionChanged" BorderThickness="1" BorderBrush="LightGray" Margin="0 0" IsReadOnly="True" GridLinesVisibility="None" Name="dataGridSongs" ItemsSource="{Binding}">
</DataGrid>
Code behind:
public MainWindow()
{
initializing = true;
InitializeComponent();
DataTable dt = dbHelper.GetAllSongs();
dataGridSongs.DataContext = dt.DefaultView;
dataGridSongs.HeadersVisibility = DataGridHeadersVisibility.None;
initializing = false;
}
The new UWP DataGrid gives me an error:
"BindingExpression path error: 'Item' property not found on 'System.Data.DataRowView'"
And the grid is populated with some strange data:
The new UWP app XAML:
<controls:DataGrid x:Name="dataGridSongs" ItemsSource="{Binding}">
</controls:DataGrid>
Code behind:
public MainPage()
{
initializing = true;
this.InitializeComponent();
DataTable dt = dbHelper.GetAllSongs();
dataGridSongs.DataContext = dt.DefaultView;
//dataGridSongs.ItemsSource = dt.DefaultView;
}
I assume I'm populating the grid with the wrong objects, however, I couldn't find any example for this simple scenario.