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

Custom XAML component in Xamarin.Forms

$
0
0

I want to create a "component" that need to use in all my pages. Under my project i have a folder where i store the component, using contextual menu (Add / New File / Forms / FormsContentView Xaml), the IDE create a two files MenuHeaderView.xaml and MenuHeaderView.xaml.cs

In the XAML file i defined this:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:SIMA.Core.Helpers;assembly=SIMA"
    xmlns:trans="clr-namespace:SIMA.Core.Helpers.Localization;assembly=SIMA"
    xmlns:const="clr-namespace:SIMA.Core.Views.Common;assembly=SIMA"
    x:Class="SIMA.Core.Views.Components.MenuHeaderView">

    <ContentView.Content>

        <!-- Menu Superior Header -->
        <StackLayout

                BackgroundColor="{x:Static const:AppConstants.ColorFondoHeader}"
                Orientation="Horizontal"
                >

            <Label Text="{trans:L10n ApplicationTitle}" 
                    Font="{x:Static const:AppConstants.FontSizeHeader}" 
                    TextColor="{x:Static const:AppConstants.ColorTextoHeader}" 
                    HorizontalOptions="CenterAndExpand" 
                    VerticalOptions="CenterAndExpand"/>

            <Label Text="[+]" Font="28" TextColor="White" HorizontalOptions="End" VerticalOptions="CenterAndExpand"/>

        </StackLayout>

    </ContentView.Content>
</ContentView>

Then, from one of my pages, first i add a new namespacexmlns:comp="clr-namespace:SIMA.Core.Views.Components;assembly=SIMA" and try to include that view using this:

<comp:MenuHeaderView></comp:MenuHeaderView>

But nothing show, it's like is ignoring the imported view.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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