Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'Mocks.MaterialDesignDemo_ColorToolViewModel_2_47133230' to type 'System.Windows.Media.SolidColorBrush'. #1411

Open
liquehuo opened this issue Sep 11, 2019 · 7 comments

Comments

@liquehuo
Copy link

@liquehuo liquehuo commented Sep 11, 2019

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

@Mrxx99

This comment has been minimized.

Copy link
Contributor

@Mrxx99 Mrxx99 commented Sep 11, 2019

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.

@liquehuo

This comment has been minimized.

Copy link
Author

@liquehuo liquehuo commented Sep 11, 2019

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 ,Thank you very much~

@jespersh

This comment has been minimized.

Copy link
Contributor

@jespersh jespersh commented Sep 11, 2019

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

@liquehuo

This comment has been minimized.

Copy link
Author

@liquehuo liquehuo commented Sep 11, 2019

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,I tried the method you said, it can be displayed normally, thank you!!

@Keboo

This comment has been minimized.

Copy link
Member

@Keboo Keboo commented Sep 11, 2019

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.

@jespersh

This comment has been minimized.

Copy link
Contributor

@jespersh jespersh commented Sep 12, 2019

@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.

@Keboo

This comment has been minimized.

Copy link
Member

@Keboo Keboo commented Sep 12, 2019

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

@Keboo Keboo added the Hacktoberfest label Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.