Failed to add <element> to ObservableCollection. Element not found Error

Viewed 947

I'm new to UWP and I'm trying to create a simple Data Grid in UWP. I'm using this link to implement a simple DataGrid but I keep having "Failed to add DataGridTextColumn to ObservableCollection. Element not found Error"

Here's the code that I'm using:

<control:DataGrid x:Name="DataGrid" HeadersVisibility="Column"
                          ItemsSource="{Binding Items}">
            <control:DataGrid.Columns>

                <control:DataGridTextColumn
                    Header="ID"
                    Binding="{Binding ID}"/>
                <control:DataGridTextColumn
                    Header="Main Statement"
                    Binding="{Binding MainStatement}"/>
                <control:DataGridTextColumn
                    Header="Question For"
                    Binding="{Binding QuestionFor}"/>
                <control:DataGridCheckBoxColumn
                    Header="Language"
                    Binding="{Binding Language}"/>
            </control:DataGrid.Columns>
</control:DataGrid>

I'm following the example and the suggestion in VS, does anyone know why is this happening? Any help is greatly appreciated!

2 Answers

I removed the Microsoft.Toolkit.Uwp.UI.Controls.DataGrid reference, built the project and added the reference again. After rebuilding MAGICALLY it worked. I'm guessing it was a VS related problem. AutoGenerateColumns property had no effect but thanks for the help. I'm gonna leave this question here maybe someone someday will face the same problem and resolve it in a different way.

Change the version number for the Grid-component in Nuget to a lower one, build, then back to the latest version seems to work. No idea why though...

Related