【问题标题】:Can the Android native CardView be used in Xamarin Forms XAML?Android 原生 CardView 可以在 Xamarin Forms XAML 中使用吗?
【发布时间】:2018-08-08 17:03:04
【问题描述】:

我已经尽我所能,但我找不到将本机 xamarin.android CardView 控件嵌入到 xamarin.forms xaml 中的方法。以下是我的代码:

我的命名空间

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"

我的 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>

我收到以下错误

Exception is: XamlParseException - Position 32:18. Can not set the content of androidWidgetv7:CardView as it doesn't have a ContentPropertyAttribute

网上有零个例子展示了如何做到这一点。有人知道吗?

【问题讨论】:

    标签: xaml xamarin.forms xamarin.android


    【解决方案1】:

    你不能。但是您可以像他们 here 那样实现类似的版本。

    您可以找到替代版本 herehere

    不要期望在这里获得 android 动画/触摸手势。

    <?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>
    

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多