Hi
I have a XamDataGrid which I want to bind to a custom collection exposed by my view model. This works fine at runtime if I specify my binding in the usual way (DataSource="{Binding Path=MyCollection}"), but this doesn't give me any design-time indication of the column layout.
I can get my columns to appear at design time by specifying the datasource collection type like so:
<Custom:XamDataGrid.DataSource> <data:MyCollectionType xmlns:data="clr-namespace:MyNamespace" /></Custom:XamDataGrid.DataSource>
However, then I can't declare my binding in XAML, as the designer complains that the DataSource is set more than once.
I can get around this by resetting the DataSource in code, but I'd prefer to keep everything declarative... Can it be done?
Hello,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I set the design DataContext of the XamDataGrid to a mock collection, so the items can be generated in the designer. I also put a second grid where you can see how to define everything in XAML and have a designer. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Hi Stefan
Thanks for your reply. It seems that the key things are to ensure that the design-time data context is set to the view model using d:DataContext (where xmlns:d="http://schemas.microsoft.com/expression/blend/2008"), and that the view model returns a collection by default... My view model was originally not returning a collection by default, because it loads data asynchronously - having changed that to return an empty collection (and setting the design-time data context) it now works.
Many thanks for your help.