Thursday, September 9, 2010

Silverlight Tips - Error : Can not create an instance of [YourUserControl]

I have frequently come across following errors in XAML file which when you are using locally created Silverlight User Control. Locally means the User Control is created and used in your own silverlight application.

Can not an instance of [Your control name].
See the screen shot of error in Visual Studio.



Even this error happens, the project still can compile and run without any problem.

How Fix the errors.
There multiple causes of this issue. My issue was caused by using BorderBrush="{StaticResource GenericBorderBrush}".
'GenericBorderBrush' is defined in App.xaml. After I move the definition of 'GenericBorderBrush' to the top of the document (it was the last definition), the problem fixed. So I can now keep the use of BorderBrush="{StaticResource GenericBorderBrush}".

So my conclusion: one of causes of error "Can not create an instance ..." is some incorrect definition in youe App.xaml which causes the definitions below it to fail.

Hope this infomraiton helps

No comments: