Inheriting XAML view

TommigunTommigun Member ✭✭
edited January 22 in Xamarin.Forms

Hi.

I have an abstract XAML content view and accompanying code-behind class.
I have two implementations of said class, both with their own XAML and code-behind class.
My intention is to add some additional controls in the deriving XAML implementations. My derived XAML classes look as such:

<?xml version="1.0" encoding="UTF-8"?>
<views:MyBasePage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:Something.Views"
             x:Class="Something.Views.MyDerivedPage"
             Title="Overriding Title">

    <ContentPage.ToolbarItems>
        ... some overriding toolbar items ...
    </ContentPage.ToolbarItems>
</views:MyBasePage >

This compiles and runs just fine, but nothing I have declared in the overriding XAML file seems to happen. The title and the toolbar items stay the same as in the base XAML file. Is this not supported or am I doing something wrong? If it's not supported, how are we supposed to handle reuse of XAML?

Thanks!

Best Answer

  • TommigunTommigun ✭✭
    Accepted Answer

    I figured it out. The deriving code-behind file must also call its InitializeComponent(). I was just calling the base constructor. Great that this is indeed supported!

    Thanks.

Answers

  • TommigunTommigun Member ✭✭
    Accepted Answer

    I figured it out. The deriving code-behind file must also call its InitializeComponent(). I was just calling the base constructor. Great that this is indeed supported!

    Thanks.

Sign In or Register to comment.