Materialdesigninxamltoolkit: Unable to cast object of type 'Mocks.MaterialDesignDemo_ColorToolViewModel_2_47133230' to type 'System.Windows.Media.SolidColorBrush'.

Created on 11 Sep 2019  路  7Comments  路  Source: MaterialDesignInXAML/MaterialDesignInXamlToolkit

Hi

After downloading the source code, I installed .netcore3.0 and .net 4.7.2. After running with vs2019, the demo can run normally but the WPF view page is prompted to report an error. The screenshot is as follows. What is the reason? Is there a library missing?

Error message

Unable to cast object of type 'Mocks.MaterialDesignDemo_ColorToolViewModel_2_47133230' to type 'System.Windows.Media.SolidColorBrush'. MaterialDesignDemo ColorTool.xaml 1

image

Hacktoberfest demo app good first issue up-for-grabs

Most helpful comment

That's only a design time error. Sadly those are very common for bigger projects and often hard to prevent. The reason for such errors is e.g. that some services/classes can't be instantiated in design time or just some things not working in design time or no design time datacontext is set...
Many also don't care because they don't use the designer. If you want to see your changes live you can try the new edit and continue feature (available since VS 2017), but this does not work for all changes.

All 7 comments

That's only a design time error. Sadly those are very common for bigger projects and often hard to prevent. The reason for such errors is e.g. that some services/classes can't be instantiated in design time or just some things not working in design time or no design time datacontext is set...
Many also don't care because they don't use the designer. If you want to see your changes live you can try the new edit and continue feature (available since VS 2017), but this does not work for all changes.

That's only a design time error. Sadly those are very common for bigger projects and often hard to prevent. The reason for such errors is e.g. that some services/classes can't be instantiated in design time or just some things not working in design time or no design time datacontext is set...
Many also don't care because they don't use the designer. If you want to see your changes live you can try the new edit and continue feature (available since VS 2017), but this does not work for all changes.

I got it 锛孴hank you very much~

If you want to, then you can replace

d:DataContext="{d:DesignInstance Type=local:ColorToolViewModel}"

with

d:DataContext="{d:DesignInstance Type=local:ColorToolViewModel, IsDesignTimeCreatable=True}"

The design context doesn't fit well here. It'll load, but have other issues instead

If you want to, then you can replace

d:DataContext="{d:DesignInstance Type=local:ColorToolViewModel}"

with

d:DataContext="{d:DesignInstance Type=local:ColorToolViewModel, IsDesignTimeCreatable=True}"

The design context doesn't fit well here. It'll load, but have other issues instead

Ok锛孖 tried the method you said, it can be displayed normally, thank you锛侊紒

Thanks @jespersh. If someone wants to submit a PR with the design time DataContext change as mentioned above I would be happy to accept it.

@Keboo it will make it load, but I don't think it is the right answer either. Instead a dedicated designmodel would be the better answer.

@jespersh yea I agree, that would be a better solution.

Was this page helpful?
0 / 5 - 0 ratings