Exception when putting a layout using xaml xamarin with android application

0

Good afternoon,

I have this code:

    <forms:SignaturePadCanvasView
    BackgroundColor="Black"
    WidthRequest="250"
    HeightRequest="350"
    StrokeColor="White"
    StrokeWidth="3"
    />
    <Button Text="test"
        Clicked="onclick" />

and when putting the layout to see the two controls, an exception jumps me saying that it does not find in ... 2014 / forms the layout info used:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"    
    android:rowCount="2"
    android:columnCount="2">


    <forms:SignaturePadCanvasView
    BackgroundColor="Black"
    WidthRequest="250"
    HeightRequest="350"
    StrokeColor="White"
    StrokeWidth="3"
    />
    <Button Text="test"
        Clicked="onclick" />

</GridLayout>

Unhandled Exception:

Xamarin.Forms.Xaml.XamlParseException: Position 8: 6. Type GridLayout not found in xmlns link

Any ideas of what may be happening?

Thanks

    
asked by Jordi Maicas Peña 29.01.2018 в 19:58
source

1 answer

0

What happens is that you are mixing XAML with Android XML (AXML). Xamarin Forms uses XAML to diagram the pages, which will be generated at runtime with the native controls of the respective platform. The XAML pages are in a shared type project, PCL or NetStandard. The android layouts are in the Xamarin Android type project and there they are created in Resources \ Layout with AXML extension.

XAML does not have GridLayout, but there is a Grid that is very similar. p>

An example page in XAML to include SignaturePad is like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:App2"
         xmlns:forms1="clr-namespace:SignaturePad.Forms;assembly=SignaturePad.Forms"
         x:Class="App2.MainPage">

<StackLayout Orientation="Vertical">

    <forms1:SignaturePadView
        x:Name="Pad"
        BackgroundColor="Gray"
        WidthRequest="100"
        HeightRequest="100"
        StrokeColor="White"
        StrokeWidth="3"
        PromptText="Prompt here"
        PromptTextColor="red"
        CaptionText="Caption this"
        CaptionTextColor="Black"

    />

    <Button Text="foo" Clicked="foobar" />
</StackLayout>

</ContentPage>
    
answered by 30.01.2018 в 15:54