Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Design Time column layout with binding to View Model
posted

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?

Parents
No Data
Reply
  • 138253
    Verified Answer
    Offline posted

    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.

    XamDataGridDesignTimeData.zip
Children