简体   繁体   English

在Xamarin表单的XAML中包含按钮时,如何解决此异常?

[英]How do I fix this exception when including a button in XAML in Xamarin forms?

I am new to XAML and Xamarin and want to build a test app on my android device. 我是XAML和Xamarin的新手,并且想在我的android设备上构建测试应用。 On the first page there's a button that directs to an other page. 在第一页上有一个指向其他页面的按钮。 Here's a piece of the C# code HomePage.xaml.cs: 这是C#代码HomePage.xaml.cs的一部分:

public void Clicked(object sender, EventArgs ea)
{
    Navigation.PushModalAsync (new SecondPage ());
}

On the second page I want to load an image and a button, but as soon as I include the button, I get this exception when running the app: java.lang.reflect.InvocationTargetException . 在第二页上,我想加载图像和按钮,但是一旦包含按钮,运行应用程序时就会出现以下异常: java.lang.reflect.InvocationTargetException Without the button, everything works fine. 没有按钮,一切正常。 Here is the xaml code of the image and the button of the second page: 这是图像的xaml代码和第二页的按钮:

<Image  Source = "image.png" 
            x:Name="image"
            VerticalOptions="Start">
    <Image.GestureRecognizers>
            <TapGestureRecognizer
            Tapped="ImageTapped"/>
    </Image.GestureRecognizers>
</Image>
<Button Text="Text"
            BackgroundColor="Aqua"
            TextColor="White"
            VerticalOptions="EndAndExpand"/>

And here the C# code of the "ImageTapped" function: 这是“ ImageTapped”函数的C#代码:

public void ImageTapped(object sender, EventArgs ea)
{
    image.IsVisible = false;
}

I have no idea what I am doing wrong and I would really appreciate it if somebody could me! 我不知道我在做什么错,如果有人可以,我将不胜感激!

在使用<ContentPage.Content>之前,我只是通过使用<StackLayout></StackLayout>解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Xamarin.Forms 页面中将 Button 作为 CommandParameter 从 XAML 传递? - How do I pass the Button as CommandParameter from XAML in a Xamarin.Forms Page? 当我单击xamarin中的按钮时,xamarin.forms发生未处理的异常 - An unhandled exception occured xamarin.forms when i click a button in xamarin 如何在Xamarin Forms中的StackLayout中放置功能正常的按钮? - How do I put a functioning button in a StackLayout in Xamarin Forms? 如何在Xamarin表单按钮上访问viewmodel命令? - How do I access my viewmodel commands on a Xamarin Forms button? 如何在其控制器中投射 XAML 项目? [C#],[Xamarin.Forms] - How do I cast an XAML item in its controller? [C#],[Xamarin.Forms] 如何在 Xamarin 表单中将 MainPage.xaml 中条目的文本属性访问到 MainActivity.cs? - How do I access the text property of an Entry in MainPage.xaml to MainActivity.cs in Xamarin forms? 如何使用 XAML 在 Xamarin.Forms 的 ListView 中选择一个项目 - How can I select an item in a ListView in Xamarin.Forms with XAML 如何在xamarin表单上做复合按钮? - How to do Composite Button on xamarin forms? 如何修复Xamarin表单中的“打开失败:errno 13”异常 - How to fix “open failed: errno 13” exception in xamarin forms 如何修复 GattStatus:3 - BLE Xamarin 表单应用程序的 WriteNotPermitted 异常? - How to fix GattStatus: 3 - WriteNotPermitted exception for BLE Xamarin forms application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM