WPF Designer DataTemplate.DataType cannot be type object
I think it wants you to use an interface type instead of a class type.
So, if you define an interface ICorrectionAndFreqViewModel
that exposes all of the properties that you'll be using for data binding and then have CorrectionAndFreqViewModel
implement that interface, you should be good.
Like you said, the code will still compile and run without using an interface here. My guess as to why the designer complains about this is that data binding can only be used on public
properties, so by using an interface, there's a guarantee that all the properties will be public
.
You should have an xmlns tag like local
, l
, or some such. In the datatype you need to use local:CorrectionAndFreqViewModel
rather than {x:Type CorrectionAndFreqViewModel}
. If you don't have one of these xmlns values then you need to define it so that it points to the dll that you're using (or use a different marker if you're looking at another project e.g. xmlns:msl="clr-namespace:MediaSystems"
)
Instead of 'object' set the 'DataType' to your actual view model type (e.g CorrectionAndFreqViewModel in your case) in properties.
Hope this will fix the issue.
Please mark it as answer if satisfies.
Ideally, it should automatically pick correct data type in properties, in my case it works correct.