0

I am new to VB.Net and .Net in general. I am building a survey application with wpf windows. Many of these windows have similar functionality, and similar class members. I thought I can use Interfaces and Abstract classes to define, and partially implement common functionality. Then, implement and inherit it in Classes of WPF windows. However, when "wpf" class inherits the abstract class, it loses the access to all regular sub routines. I realize I do some fundamental mistake here. Can anyone explain me how do I implement common functionality, and define common members, and then use it in different WPF windows ?

2
  • What exactly do you mean by "it loses the access to all regular subroutines"? When you inherit a class you should be gaining the functionality of the inherited class as well as have any additional functionality you add in the inheriting class. Commented Mar 22, 2013 at 0:09
  • This is exactly what I expected, but the "wpf class" lost access to any Window subroutines after inheriting my abstract class. And I do not see where "wpf classes" get these Window subroutines. My goal is to define some common subroutines, and some implementation for these subroutines, that I can later use in all my WPF Windows. Commented Mar 22, 2013 at 1:11

1 Answer 1

1

I'm not entirely sure I follow what your problem is, but if you have a WPF window inherit a class which is not itself at least derived from WPF Window, or which hides the members of the window class to its descendants, you will loose the functionality of the WPF window class.

Say I have class MyWPFWindowClass which inherits from System.Windows.Window and therefore has all the methods of a window.

If you now have it inherit from a new class MyWPFWindowClassBase instead, MyWPFWindowClass will instead have all the methods of MyWPFWindowClassBase.

Now, unless MyWPFWindowClassBase itself inherits from System.Windows.Window and therefore has all the methods of a window, you will not have those methods available in MyWPFWindowClass or any other class derived from MyWPFWindowClassBase.

I hope that does make it a bit clearer?

Have a look at this link to get you started on inheritance in .Net.

Sign up to request clarification or add additional context in comments.

4 Comments

This looks like what is happening to my wpf classes when they inherit from an abstract class. All Window is overridden. My confusion was because I do not see classes under wpf .xaml files explicitly inheriting Window. Where does wpf class gets Window functionality? For my purpose, should I just make abstract class inherit Window, and then "wpf class" inherit that abstract class? Will it work? Thanks.
Unfortunately I do not have much experience with WPF itself (I do mostly still Winforms...), but I think this post will help you weblogs.asp.net/psheriff/archive/2009/11/02/…
Otherwise, you can go to the code behind file of your window and tell it to inherit your class ... : Inherit MyClass. You will get an error in the .g.vb file. If you change that to inherit from the same class as well it should work (I just tried it). If you have your abstract class inherit from Window and then add custom methods to it and then have your other classes inherit from that it should work just fine. Just make sure that you get the accessors on the methods you want to expose correct though.
The way I would do it, is start by adding a new window, and make that my BaseClass, so it already inherits from Window and all is done correctly by the designer and then add functionality to that in the code-behind file or change the xaml to modiffy the appearance and then pass that class on to all my custom controls (I apologies for saying this if you already knew how to do all this).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.