I am using WPF and I'm trying to make a class inherit from UserControl
and use that class as a base class for other classes. I've read numerous articles on how to do this (such as this one which has over 50 upvotes), but they all say the same thing and none of them work.
I have this code:
namespace MyNamespace {
// handwritten
public class BaseControl : UserControl { }
// generated by the IDE
public partial class XAMLControl1 : UserControl {
...
}
}
Now, I change that line to
public partial class XAMLControl1 : BaseControl {
And in the XAML, I change it from
<UserControl x:Class="MyNamespace.XAMLControl1" ...>
...
</UserControl>
To
<my:BaseControl x:Class="MyNamespace.XAMLControl1"
xmlns:my="clr-namespace:MyNamespace" ...>
...
</my:BaseControl>
The my:BaseControl
part is underlined in squiggly blue, so when I hover it, IntelliSense says
The name "
BaseControl
" does not exist in the namespace "clr-namespace:MyNamespace
".
And the compiler gives me the strange errors
Closing tag for element '<m>' was not found.
The type '
m
' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.The name "
BaseControl
" does not exist in the namespace "clr-namespace:MyNamespace
".
Yes, that's "The type 'm
' was not found". I don't see where I'm trying to use a type named m
anywhere. I think this is an unrelated compiler bug, but I thought I'd mention it. And also I'm definitely sure the type BaseControl
does exist in the namespace MyNamespace
. Intellisense comes up with no suggestions after I type the my:
.
What can I do to fix this problem? I am using Visual Studio 2012 Express for Windows Desktop (7).