Reputation: 16413
I've messed around as best I can but I can't find a way to embed the native xamarin.android CardView control within xamarin.forms xaml. Following is my code:
my namespaces
xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
xmlns:androidWidgetv7="clr-namespace:Android.Support.V7.Widget;assembly=Xamarin.Android.Support.v7.CardView;targetPlatform=Android"
xmlns:androidLocal="clr-namespace:MyApp.Droid;assembly=MyApp.Android;targetPlatform=Android"
My Xaml
<androidWidgetv7:CardView x:Arguments="{x:Static androidLocal:MainActivity.Instance}" View.HorizontalOptions="Center" View.WidthRequest="600" View.HeightRequest="300">
<androidWidget:TextView x:Arguments="{x:Static androidLocal:MainActivity.Instance}" Text="Simple Native Color Picker" TextSize="24" View.HorizontalOptions="Center"/>
</androidWidgetv7:CardView>
I get the following error
Exception is: XamlParseException - Position 32:18. Can not set the content of androidWidgetv7:CardView as it doesn't have a ContentPropertyAttribute
There are zero examples on the web showing how to do this. Anyone know?
Upvotes: 0
Views: 571
Reputation: 4436
You can't. but you can implement a similar version of it like how they did here.
you can find alternative versions here and here.
Don't expect to get android animations/touch gestures here.
<?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:gravity="center_horizontal"
android:padding="5dp">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="245dp"
android:layout_gravity="center_horizontal">
<TextView
android:text="Basic CardView"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</android.support.v7.widget.CardView>
</LinearLayout>
Upvotes: 1