locked
Simple inheritance, how???

    Question

  • Ok so I started porting my Windows Phone 7 app to Windows 8 recently.  One of the foundations of my Windows Phone 7 app is the INotifyPropertyChanged interface.

    I have a bunch of view models which implement this interface.  In every single app I have written, I use the same pattern.  I create a base class which implements the interface, and implements some public function which executes the event handler, etc. etc.  I do this because every one of my view models inherits from it, so I don't have to write this same code over again.

    In Windows 8, I can't for the life of me figure out how to accomplish this.  I can't inherit from my own classes if they are public, and yet it's a compiler error if the base class is less visible (ie not public).

    Anyone got a solution?  Or I am destitute to copy/pasting this code everywhere??

    Thursday, November 01, 2012 1:11 AM

Answers

  • The standard suggestion applies: if you don't get an answer try providing more information about what you are doing and what you have tried to solve this yourself.

    I'm not sure what you mean by this sentence:  I can't inherit from my own classes if they are public, and yet it's a compiler error if the base class is less visible (ie not public).

    Is this backwards? What do you mean you can't inherit from public classes? What error do you get if the base class is not public?

    Have you tried marking your classes internal so they are visible within your component but not projected outside of it?

    --Rob

    • Marked as answer by Jesse Jiang Thursday, November 08, 2012 6:10 AM
    Friday, November 02, 2012 4:09 AM
    Owner
  • In addition to Rob's suggestions, you could find out by example and create a new 'Grid App' templated solution. You should find pertinent answers in the following code hierarchy:
    - \DataModel\SampleDataSource: different data model [view model] concrete classes [SampleDataGroup, SampleDataItem] that reference SampleDataCommon
    - \Common\BindableBase: a class that notifies property changes and is referenced by SampleDataCommon
    Friday, November 02, 2012 6:38 AM

All replies

  • Anyone?

    Friday, November 02, 2012 12:48 AM
  • The standard suggestion applies: if you don't get an answer try providing more information about what you are doing and what you have tried to solve this yourself.

    I'm not sure what you mean by this sentence:  I can't inherit from my own classes if they are public, and yet it's a compiler error if the base class is less visible (ie not public).

    Is this backwards? What do you mean you can't inherit from public classes? What error do you get if the base class is not public?

    Have you tried marking your classes internal so they are visible within your component but not projected outside of it?

    --Rob

    • Marked as answer by Jesse Jiang Thursday, November 08, 2012 6:10 AM
    Friday, November 02, 2012 4:09 AM
    Owner
  • In addition to Rob's suggestions, you could find out by example and create a new 'Grid App' templated solution. You should find pertinent answers in the following code hierarchy:
    - \DataModel\SampleDataSource: different data model [view model] concrete classes [SampleDataGroup, SampleDataItem] that reference SampleDataCommon
    - \Common\BindableBase: a class that notifies property changes and is referenced by SampleDataCommon
    Friday, November 02, 2012 6:38 AM