无法从本机句柄激活类型为Com.ViewPagerIndicator.CirclePageIndicator的实例

时间:2019-03-13 14:22:47

标签: xamarin xamarin.forms xamarin.android

我只是在Android端收到此错误。我在我的2页上使用CarouselView.FormsPlugin作为滑块。第一个是作为导航页面的注册表。之后,使用带标签的主页,其中有另一个用于显示图像的滑块。

当我单击“下一步”按钮完成注册表时,会出现该错误。

    private void NavButton_Clicked(object sender, EventArgs e)
    {
        App.Current.MainPage = new TabbedPage1();
    }

完整错误:未处理的异常:

System.NotSupportedException:无法从本机句柄0xbfe3d69c(key_handle 0x9d8c998)激活Com.ViewPagerIndicator.CirclePageIndicator类型的实例。发生

在iOS上以及在注册页面上移除滑块时,我没有收到任何错误消息。

这是我首先显示的方式(注册表单滑块):

                <controls:CarouselViewControl ItemsSource="{Binding QuestionList}"
                                      VerticalOptions="FillAndExpand"
                                      ShowIndicators="True"
                                      ShowArrows="False"
                                      Position="0"                                          
                                      IndicatorsTintColor="White"
                                      CurrentPageIndicatorTintColor="#ffc625"
                                      AnimateTransition="True">
                    <controls:CarouselViewControl.ItemTemplate>
                        <DataTemplate>
                            <StackLayout>
                                <aboutmydogquestionviews:AnswerboxQuestionView QuestionText="{Binding Q1.QuestionText}" HeightRequest="233"
                             QuestionSubText="{Binding Q1.QuestionSubText}" ShowAnswer="{Binding Q1.ShowAnswer}" ></aboutmydogquestionviews:AnswerboxQuestionView>
                                <aboutmydogquestionviews:AnswerboxQuestionView QuestionText="{Binding Q2.QuestionText}" HeightRequest="233" IsVisible="{Binding Q2,Converter={StaticResource IsNull}}"
                             QuestionSubText="{Binding Q2.QuestionSubText}" ShowAnswer="{Binding Q2.ShowAnswer}" ></aboutmydogquestionviews:AnswerboxQuestionView>
                            </StackLayout>
                        </DataTemplate>
                    </controls:CarouselViewControl.ItemTemplate>
                </controls:CarouselViewControl>

2 个答案:

答案 0 :(得分:1)

这是项目CarouselView.FormsPlugin的错误。

要修复此问题,您需要将同一作者的一个名为CirclePageIndicator (v1.0.3)的项目添加到Android项目中(或者您可以等待作者修复Carousel插件)。

答案 1 :(得分:0)

  

您在Mainpage中有一个CarouselViewControl控件,在CarouselViewControl中有两项,当您浏览第二页时,您想单击按钮以用TabbedPage1替换项目当前的MainPage

如果要执行此操作,我将提供一个示例供您查看,但不会收到任何错误消息。

Page7.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
  x:Class="test2.Page7"
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:abstractions="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions">
<abstractions:CarouselViewControl
    ItemsSource="{Binding pages}"
    Orientation="Horizontal"
    PositionSelectedCommand="{Binding Mycommand}"
    ShowArrows="true"
    ShowIndicators="true">
    <abstractions:CarouselViewControl.ItemTemplate>
        <DataTemplate>
            <ContentView Content="{Binding .}"/>
        </DataTemplate>

    </abstractions:CarouselViewControl.ItemTemplate>
</abstractions:CarouselViewControl>

</ContentPage>

public partial class Page7 : ContentPage
{
    public Page7()
    {
        InitializeComponent();
        Title = "CarouselView";
        this.BindingContext = new MainViewModel1();
    }    
}

ViewModel:

class MainViewModel1
{
    public List<ContentView> pages { get; set; }
    public Command Mycommand { get; set; }

    public MainViewModel1()
    {
        pages = new List<ContentView>();
        pages.Add(new View1());
        pages.Add(new View2());

        Mycommand = new Command(() =>
        {
            Console.WriteLine("Position selected!!!!!!!!!!!!!!");
        });          
    }
}

View1.cs,这是contentview

public class View1 : ContentView
{
    public View1 ()
    {
        Content = new StackLayout {
            Children = {
                new Label { Text = "Welcome to Xamarin.Forms!" }
            }
        };
    }
}

View2.cs,这是contentview

public class View2 : ContentView
{
    public View2 ()
    {
        Content = new StackLayout {
            Children = {
                new Label { Text = "Welcome to Xamarin.Forms!" },
                new Button{Text="btn1", WidthRequest=80,HeightRequest=50,Command=new Command(()=>{App.Current.MainPage=new TabbedPage1(); })}

            }
        };
    }
}

enter image description here