[英]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.