We use the xmlns:local keyword to specify our class as a reference (in my case, WinTest). This way, we could use into XAML each class defined within our namespace (in my case, Articolo). We then define three DataGridColumns, each one binded with a specific property of our class. Then, with the tag local, we could proceed in defining a variable number of records, setting each of its parameters. The code above will produce the following window: From a situation like that, we could add other rows code-side, using the Item collection exposed by DataGrid. Supposing our DataGrid's name is DataGrid1, we could, for example, add a second row to it, using in the Loaded event something like that:
Running now our program will result in the following window: Please note: as far as there are dynamically or statically generated rows, i.e. the Item collection is not empty, it's not possibile to use the ItemsSource property discussed above. In order to bind a structure to our DataGrid, we must first empty Item collection (for example, with something like: DataGrid1.Items.Clear()), and only after that we'll be able to successfully set the ItemsSource property.
Thanks for share.