Expression Blend: I made a copy of a UserControl and now it throws an error
Don’t you hate it when you are going to do a simple thing like copy a UserControl and then it doesn’t work? Seriously, how can you steal other peoples work if you have to redo all of their code.
Well first of all, make sure you tell others about the work that you are using, and if the artist or creator asks that you pay for the work, then pay for it or don’t use it.
Now down to business, why can’t you just make a copy of a UserControl and put it to use right way?
Simple, the code behind can’t determined which XAML it is suppose to use:
Now I just copied Christine’s Dancing heart project and was going to break it, I did when I simply copied the user control. My code behind looked like this:
The red squiggly lines mean that something is wrong, and the error seems kind of stupid, but it is unambiguous in it’s statement of ambiguity.
You now have two of these in your program, the line x:Class=”DancingHeart.DancingImage” is repeated twice, once in the copy of the UserControl and once in the original copy.
The Fix:
Change the Copy X:Class
from:
x:Class=”DancingHeart.DancingImage”
to:
x:Class=”DancingBrokenHeart.DancingImage”
Also you might consider copying the image and changing the image name.
Finally you will need to fix the attached code behind by changing the class constructor name
from
public DancingImage()
to:
public DancingBrokenImage()
And it will look like the following:
Once you do this then the ambiguous situation will go away.