Forum Xamarin.Forms

Inheritance On ContentViews \ Page

JungleJungle Member ✭✭

I want some of my ContentViews to have a common custom constructor, for example;

        public ContentViewName(BindableObject indexview) : this()
            BindingContext = indexview.BindingContext;

but the partial class already inherits from ContentView (c# only allows one parent class, and an interface wouldn't help here).

The work around I thought of was to create a custom Contentview, which includes this constructor and derive from that.

How can this be achieved? (I have tried and failed)


  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 2018

    It is just the extension of class constructor .

    Custom Constructor .

        public string s;
        public View1(string str)
            s = str;


       View1 view = new View1("test");
  • JungleJungle Member ✭✭

    I understand a constructors with different signatures.

    What I want is all my ContentView's to all have a base class that already has this implemented.

    My problem is ContentView's already inherit (from its self) this means that my "Custom ContentView" will also have to inherit the ContentView Class, this is the implementation I can't get working.

Sign In or Register to comment.