Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Extending a base class in XAML

$
0
0

Hi There

So I found myself making a bunch of views that have very similar functionality and wanted to make them extend from a base class. Originally these were custom XAML extending ContentView:

<ContentView xmlns="//xamarin.com/schemas/2014/forms"
             xmlns:x="//schemas.microsoft.com/winfx/2009/xaml"
             xmlns:layouts="clr-namespace:MyApp.Layouts"
             x:Class="MyApp.Layouts.CommentPopUp">
//Content
</ContentView>

What I was hoping I could do, was make a new class PopUpBase that extended from ContentView and implemented some of the functionality for these views, then extend that. I'm not sure how to refer to it though, trying it like this compiles but crashes when the view is displayed:

<layouts:PopUpBase xmlns="//xamarin.com/schemas/2014/forms"
             xmlns:x="//schemas.microsoft.com/winfx/2009/xaml"
             xmlns:layouts="clr-namespace:MyApp.Layouts"
             x:Class="MyApp.Layouts.CommentPopUp">
//Content
</layouts:PopUpBase>

Is this possible? If so, how? If not, what alternatives do I have to writing out identical code for each layout?

Thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>