Guys I am new to WPF .
I have a wpf page named StandardsDefault
. In the code behind, StandardsDefault
is inheriting Page
, l
You have to change your CountryStandards XAML to:
<src:StandardsDefault x:Class="namespace.CountryStandards"
xmlns:src="NamespaceOfStandardsDefault" ... />
There is a good article about inheriting from a custom Window/Page in WPF.
For me : the partial codebehind class must not define any base class at all, even the same base class!
The error message is confusing.
WRONG:
xaml:
<someNamespace:SomeBaseClass x:Class="My.Namespace.ClassName" ...
C#:
namespace My.Namespace
{
public partial class ClassName : SomeBaseClass
{
}
}
RIGHT:
xaml:
<someNamespace:SomeBaseClass x:Class="My.Namespace.ClassName" ...
C#:
namespace My.Namespace
{
public partial class ClassName
{
}
}
Posting this just because I ran into a similar issue, albeit not the same, but maybe it will help somebody. I initially started with a UserControl, but then changed my control to inherit from Button. But, the XAML wasn't updated along side it automatically, so I forgot to change my XAML from UserControl to Button as well. It should be:
<Button x:Class="ThermostatGui.Shared.Controls.SetpointButton" .../>
not this
<UserControl x:Class="ThermostatGui.Shared.Controls.SetpointButton" .../>
Make sure other partial classes are not extending a different class.
public partial class CountryStandards : StandardsDefault
public partial class CountryStandards : Page
You have to make them extends same class.
You need to use StandardsDefault as root node since you are creating a user control.since you are using page as root node c# compiler expects page as base. but in your you are using StandardsDefault as base so you need to use StandardsDefault as root node then it will work.
Bit of an odd one, and it hasn't been listed here yet... But since none of the above answers applied because I had both my xaml and cs files declared correctly, I did the following and it seemed to work:
Go into the solution folder or click the show all files buton within Visual Studio and delete both the obj and bin folders, this causes Visual Studio to regenerate all of its files for the project.
Your project should now build/run correctly.
Hope that helps someone - or perhaps myself in the future.
Edit: This fix usually works if you get this problem after changing the page type from for example a ContentPage to a CarouselPage.