I have static data that I want to display in Datagrid format. The values are for display purposes only and will not change. Can it be added as some kind of subtag of the Datagrid control so I can avoid anything in the codebehind?
It has to be Datagrid control only as the purpose is to experiment with and demo certain Datagrid UI features with dummy blah blah content.
If pure XAML content is not possible then what is the best (quick & dirty) method to set up dummy content for a datagrid? Can it be done without writing classes etc?
Here is pure XAML static data binded on a datagrid:
Result:
I wasn't able to autogenerate columns using XmlDataProvider (I'm probably missing something):
But using a code Behind class like Dave Suggestion allow AutoBinding to work and in my opinion is much simpler (I preferred the
ResourceDictionary
approach though) :Code:
XAML
You can do static data in XAML, yes, but you will need to create a simple class for the record format. For example, you could create this class file:
Now in your XAML DataGrid you can do this:
Check the example section on this MSDN page
Since the datagrid uses ItemsControl similar to Combobox or ListBox, datagrid should be the same logic. In that example they basically create a whole collection of objects in pure XAML.