Similar to creating a data binding in Windows Forms designer, I am creating a databound item on my blank WPF control by dragging and dropping the property of my custom simple object onto it from the Data Sources window. It creates the expected label with the data field name and text box control, and compiles fine. But when I run the application it throws the following error:
{“Unable to cast object of type ‘System.Windows.Controls.Grid’ to type ‘System.Windows.Data.CollectionViewSource’.”}
How do I fix it?
The markup generated by the designer doesn’t work. The
Gridthat’s nested around the label and text box has aDataContextproperty of the form{StaticResource mySimpleObjectViewSource}, but needs to be of the form{Binding Source={StaticResource mySimpleObjectViewSource}}.