来自AlexRainman的CarouselView无法在iOS上呈现,在Android上运行良好。 Xamarin.Forms

时间:2017-05-24 14:23:22

标签: android ios xamarin xamarin.forms

我无法从AlexRainman制作CarouselView控件。控件在Android上呈现正常,但在iOS上则不行。我的项目是适用于iOS和Android的Xamarin PCL项目,目前正在为macOS的Visual Studio 2017工作。并坚持这一点,并不知道如何解决这个错误。任何帮助将不胜感激。

我的内容页面:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="PelotaJara.BookingUserPage"
         xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"

         >
    <controls:CarouselViewControl x:Name="carousel" IndicatorsTintColor="Gray" ShowIndicators="True"  
                              CurrentPageIndicatorTintColor="Black"  Orientation="Horizontal" InterPageSpacing="10" 
                              VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"  AnimateTransition="true" IsSwipingEnabled="true">
        <controls:CarouselViewControl.ItemTemplate>
            <DataTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30*" />
                    <RowDefinition Height="50*" />
                    <RowDefinition Height="20*" />

                </Grid.RowDefinitions>


                    <Image Grid.Row="0"  VerticalOptions="Start" HorizontalOptions="CenterAndExpand"  Source="{Binding Image}"/>
                    <Label  Grid.Row="0" Text="Cancha Iluminada"  TextColor="White" HorizontalOptions="Center" VerticalOptions="End"/>
                    <Button Grid.Row="2" Text="Reservar" BackgroundColor="Red" HorizontalOptions="Fill" VerticalOptions="Center" TextColor="White"/>


            </Grid>
        </DataTemplate>
        </controls:CarouselViewControl.ItemTemplate>
    </controls:CarouselViewControl>

守则背后:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BookingUserPage : ContentPage
{   
    ObservableCollection<CarouselModel> model { get; set; }  
    public BookingUserPage()
    {
        InitializeComponent();



        model = new ObservableCollection<CarouselModel>();

        carousel.ItemsSource = model;

        model.Add(new CarouselModel("http://seattlerats.org/wp-content/uploads/2015/03/Soccer-Field-Night.jpg"));
        model.Add(new CarouselModel("http://seattlerats.org/wp-content/uploads/2015/03/Soccer-Field-Night.jpg"));
        model.Add(new CarouselModel("http://seattlerats.org/wp-content/uploads/2015/03/Soccer-Field-Night.jpg"));




    }



}

public class CarouselModel
{
    public CarouselModel(string imageString)
    {
        Image = imageString;
    }
    private string _image;
    public string Image
    {
        get { return _image; }
        set { _image = value; }
    }
}

Appdelegate.cs:

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {


        ServicePointManager
          .ServerCertificateValidationCallback +=
          (sender, cert, chain, sslPolicyErrors) => true;


        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());

        CarouselViewRenderer.Init();

        return base.FinishedLaunching(app, options);
    }

最后,我的MainActivity.cs:

    [Activity(Label = "PelotaJara", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {

        ServicePointManager
.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        CarouselViewRenderer.Init();

        LoadApplication(new App());
    }
}

2 个答案:

答案 0 :(得分:0)

我的问题可能不完全是你所拥有的,但在这里我是如何解决它的:它在版本CarouselView.FormsPlugin 4.4.1和Xamarin表格2.3上运行良好...工作正常更新旋转木马视图到4.4.3 iOS休息Android工作正常,我在github上提交了一个问题,似乎已经解决,所以尝试将其更新到最新版本,xamarin表格到2.4.0应该可行。这是github上的问题:https://github.com/alexrainman/CarouselView/issues/210

答案 1 :(得分:0)

您的AppDelegate错误,应该是:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{


    ServicePointManager
      .ServerCertificateValidationCallback +=
      (sender, cert, chain, sslPolicyErrors) => true;


    global::Xamarin.Forms.Forms.Init();
    CarouselViewRenderer.Init();
    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}