Reputation: 1117
Is it possible to extend the "Page"-class in C#'s WPF-toolkit (or, respectively, any other WPF-class)? What i tried to do:
public class ExtendedPage : Page{
protected void doStuff(){
// lots of joy n pleasure
}
}
public partial class RandomWindow : ExtendedPage{
private void randomMethod(){
doStuff(); // causes error
}
}
The reason I'm asking is pretty obvious: After extending the Page-class (ExtendedPage), the subclass (RandomWindow) has no acces to the methods of its base. This (at least it's my guess) caused by the circumstance of RandomWindow being partial. Since this class unfortunately is generated by WPF (links to the corresponding *.xaml), I'm unable to locate the other part of the partial-class.
This question might lead to a pretty obvious answer that makes me look like a total moron, but apprently I'm unable to figure it out. I might add that I've just started working with C#, my programming origin is Java.
The exact error-message is "Partial declarations of 'type' must not specify different base classes" (CS0263).
As response to one of the comments: The declaration of "Page" in the *.xaml seems to generate an code-behind-file whose base-class is "Page" (and not ExtendedPage). Changing this seems not to work either, the compiler complains about the type ExtendedPage not being found.
<Page x:Class="...RandomWindow" ... />
// to
<src:ExtendedPage x:class="...RandomWindow"
xlmns:src="...ExtendedPage" />
Upvotes: 6
Views: 3053
Reputation: 184516
Partial declarations of 'type' must not specify different base classes
Well, that one's a no-brainer, you probably have a XAML somewhere which looks like this:
<Page x:Class="MyApp.MyNamespace.RandomWindow" ....>
Implicitly specifying a Page
as the base, you need however:
<local:ExtendedPage x:Class="MyApp.MyNamespace.RandomWindow"
xmlns:local="clr-namespace:MyApp.NSContainingExtendedPage"
...>
Upvotes: 7
Reputation: 62246
After extending the Page-class (ExtendedPage), the subclass (RandomWindow) has no acces to the methods of its base
This is wrong. Extending a class, if it's possible, gain you access to all public
and protected
members of base class.
Partial is related only to destribution of the code of the class among different files, but has nothing to do with it's real presentatioon after compilation. After compilation it becomes one single and solid type.
What you posted here should work fine.
Upvotes: 0