CollectionViewSource d:DesignSource Property
CollectionViewSource d:DesignSource property does not function properly when used to expose design time sample data using the Source property of d:DesignSource.
Issue One – DataGrid Design-Time Feature Disabled
After completing a drag and drop operation from the Data Sources Window to create a DataGrid in a WPF or Silverlight application the following XAML is placed in the root layout panel resources section:
<CollectionViewSource x:Key="PersonViewSource" d:DesignSource="{d:DesignInstance my:Person, CreateList=True}" />
In the above XAML, the Person class was used as the object source.
Normally d:DesignSource would expose the list of Person’s created by d:DesignInstance. However the d:DesignSource feature is not working properly and does not exposed the types created by d:DesignInstance.
The negative side effect is that the DataGrid design time features are disabled. For this reason, when right-clicking in the Data Grid you will see that "Generate Columns" and "Edit Property-Bound Columns" menu items are greyed out, and the corresponding features in the property grid's Columns editor will not work.
The Columns Collection can still be edited using the Collection ellipses button to open the Columns Editor dialog box.
Issue Two – Sample Data Can’t Be Exposed Through The d:DesignSource Property
Example:
<local:Animals x:Key="animals"/>
<CollectionViewSource x:Key="cvs1" d:DesignSource="{Binding Path=AnimalList, Source={StaticResource animals}}" />
In the above XAML the developer has an Animals class that loads up instances of Animal in its constructor.
Normally d:DesignSource would contain the collection of Animal’s and this collection would be available on the design surface for consumption as sample data. However the d:DesignSource feature is not working properly and does not exposed the types rendered by the Binding.
Issue Three – d:DesignData Sample Data Can’t Be Exposed Through The d:DesignSource Property
Example:
<CollectionViewSource x:Key="cvs" d:DesignSource="{d:DesignData Source=../SampleData/PersonSampleData.xaml}" />
In the above XAML the developer has a collection of Person class in the PersonSampleData.xaml file. Normally the collection of Person’s would be exposed by the d:DesignSource property and would be available on the design surface for consumption as sample data. However the d:DesignSource feature is not working properly and does not exposed the types rendered by d:DesignData.
Workaround For Surfacing Sample Data
Example:
<Grid d:DataContext="{d:DesignData Source=../SampleData/PersonSampleData.xaml}">
To surface sample data on the design surface, assign a d:DataContext and assign this property d:DesignData as in the above XAML or bind to a resources that returns a collection as in the example in Issue One above.