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 ?
-
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.yu_ominae– yu_ominae2013-03-22 00:09:43 +00:00Commented 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.vlr– vlr2013-03-22 01:11:33 +00:00Commented Mar 22, 2013 at 1:11
1 Answer
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.
4 Comments
... : 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.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).