Xamarin Forms: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

后端 未结 2 994
予麋鹿
予麋鹿 2021-02-15 18:09

I am struggling with this issue. I created just a simple cross platform page here is XAML code:




        
相关标签:
2条回答
  • You have mistake in your Carousel page

    <?xml version="1.0" encoding="utf-8" ?>
    <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="ForTesting.TestPage">
      <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
      <ContentPage>
        <ContentPage.Padding>
          <OnPlatform x:TypeArguments="Thickness" iOS="0,40,0,0" Android="0,40,0,0" />
        </ContentPage.Padding>
      </ContentPage>
    </CarouselPage>
    

    Carousel page should have only one child, and it should be a ContentPage, you won't be able to add both label and content page. Remove this line

     <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
    

    If you want to have both label and content in a Carousel, I would suggest using something like CarouselView.

    EDIT 1

    I've create a sample Carousel project with latest Xamarin.Forms (2.2.0.31), I've tested it on iOS and Android and it works. You can use it as a starter to implement your version. I use this control in production app.

    0 讨论(0)
  • 2021-02-15 18:50

    In general, I've noticed that any syntax errors in XAML may show up as this exception.

    0 讨论(0)
提交回复
热议问题