找不到类型为CarouselView.FormsPlugin.Android.CarouselViewRenderer

时间:2017-11-25 13:54:54

标签: c# android xamarin xamarin.forms carousel

我正在尝试将CarouselView添加到我的Xamarin.Forms项目中。我在XAML中直接添加控件而没有任何像这样的绑定:

<cv:CarouselViewControl>
   <cv:CarouselViewControl.ItemsSource>
      <x:Array Type="{x:Type View}">
         <Label Text="Page 1"/>
         <Label Text="Page 2"/>
         <Label Text="Page 3"/>
      </x:Array>
   </cv:CarouselViewControl.ItemsSource>
</cv:CarouselViewControl>

我还在IOS和Android项目中初始化了控件。

Xamarin.Forms.Forms.Init(this, bundle);
CarouselViewRenderer.Init();
LoadApplication(new App());

但是在运行项目时,它会在LoadApplication(new App());

处抛出此错误
System.MissingMethodException: Default constructor not found for type CarouselView.FormsPlugin.Android.CarouselViewRenderer

查看source,很明显渲染器只有一个带有一个参数的构造函数。我不确定我需要做些什么来解决这个问题,但我确信有些东西我不知道。

更新

以下是所要求的代码:

MainActivity.cs
using System;    
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.Iconize;
using FormsPlugin.Iconize.Droid;
using CarouselView.FormsPlugin.Android;

namespace One.Droid
{
    [Activity(Label = "One", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
            Xamarin.Forms.Forms.Init(this, bundle);
            IconControls.Init(Resource.Id.toolbar, Resource.Id.tabMode);
            CarouselViewRenderer.Init();
            var app = new App();
            app.TriggerFullScreenSwitch += (s) => { if (s) MakeFullScreen(); else ExitFullScreen(); };
            LoadApplication(app);
            MakeFullScreen();
        }

        /// <summary>
        /// Makes it the full screen.
        /// </summary>
        private void MakeFullScreen()
        {
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            int uiOptions = (int)Window.DecorView.SystemUiVisibility;
            uiOptions |= (int)SystemUiFlags.HideNavigation;
            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
        }
        /// <summary>
        /// Exits the full screen.
        /// </summary>
        private void ExitFullScreen()
        {
            Window.ClearFlags(WindowManagerFlags.Fullscreen);
            Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
        }
    }
}
XAML
<?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:One"
             xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
             x:Class="One.Showcase" local:XamarinPage.ShowFullScreen="true">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <cv:CarouselViewControl>
                <cv:CarouselViewControl.ItemsSource>
                    <x:Array Type="{x:Type View}">
                        <Button Text="Page 1"/>
                        <Label Text="Page 2"/>
                        <Label Text="Page 3"/>
                    </x:Array>
                </cv:CarouselViewControl.ItemsSource>
            </cv:CarouselViewControl>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>
Xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace One
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Showcase : ContentPage
    {
        public Showcase ()
        {
            InitializeComponent ();
        }
    }
}

0 个答案:

没有答案