How can i use Xamarin.Forms ContentView in xamarin Android Main.xml

59 Views Asked by At

I create a ContentView in xamarin forms and i want to use it in Main.xml in the xamarin android

 [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SwapPage : ContentView
    {
        public SwapPage()
        {
            InitializeComponent();
        }

        double? layoutHeight;
        double layoutBoundsHeight;
        int direction;
        const double layoutPropHeightMax = 0.75;
        const double layoutPropHeightMin = 0.04;
        private void PanGestureHandler(object sender, PanUpdatedEventArgs e)
        {
            layoutHeight = layoutHeight ?? ((sender as StackLayout).Parent as AbsoluteLayout).Height;
            switch (e.StatusType)
            {
                case GestureStatus.Started:
                    layoutBoundsHeight = AbsoluteLayout.GetLayoutBounds(sender as StackLayout).Height;
                    break;
                case GestureStatus.Running:
                    direction = e.TotalY < 0 ? 1 : -1;
                    var yProp = layoutBoundsHeight + (-e.TotalY / (double)layoutHeight);
                    if ((yProp > layoutPropHeightMin) & (yProp < layoutPropHeightMax))
                        AbsoluteLayout.SetLayoutBounds(bottomDrawer, new Rectangle(0.5, 1.00, 0.9, yProp));
                    break;
                case GestureStatus.Completed:
                    if (direction > 0) // snap to max/min, you could use an animation....
                    {
                        AbsoluteLayout.SetLayoutBounds(bottomDrawer, new Rectangle(0.5, 1.00, 0.9, layoutPropHeightMax));
                        swipeLabel.Text = "Swipe me down";
                    }
                    else
                    {
                        AbsoluteLayout.SetLayoutBounds(bottomDrawer, new Rectangle(0.5, 1.00, 0.9, layoutPropHeightMin));
                        swipeLabel.Text = "Swipe me up";
                    }
                    break;
            }
        }
    }

This is my ContentView and

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="100"
    xmlns:local="clr-namespace:......Pages">

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_weight="90"/>

    <local:SwapPage
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
   
</LinearLayout>

and the error is

Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class SwapPage'

0

There are 0 best solutions below