简体   繁体   English

Xamarin Forms按钮单击事件在运行时崩溃

[英]Xamarin Forms button click event crashes when running

I'm editing an application in Xamarin targeting: Windows, iOS and Android. 我正在Xamarin中定位应用程序:Windows,iOS和Android。

In the portable project, when editing the xaml file I added this button: 在可移植项目中,当编辑xaml文件时,我添加了以下按钮:

<Button 
    x:Name="Marker_Detection" 
    Text="Marker Detection" 
    Grid.Row="0" 
    Grid.Column="0" />

All goes well. 一切顺利。

Then I added the click name function for the button: 然后,我为按钮添加了点击名称功能:

<Button 
    x:Name="Marker_Detection" 
    Text="Marker Detection" 
    Grid.Row="0" 
    Grid.Column="0" 
    Click="MarkerDetectionClick" />

The project builds fine, but crashes in the execution. 该项目构建良好,但在执行时崩溃。 It stops at the line below, in the file App.gics : 它停在文件App.gics中的以下行:

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
        UnhandledException += (sender, e) =>
        {
        --->STOP HERE--->   
            if (global::System.Diagnostics.Debugger.IsAttached) 
                global::System.Diagnostics.Debugger.Break();
        };
#endif
}

What is the solution for the this problem? 该问题的解决方案是什么?

The event is called Clicked, not Click in Xamarin Forms, so your XAML is invalid, and that's why it's failing. 该事件在Xamarin表单中称为Clicked,而不是Click,因此您的XAML无效,这就是失败的原因。 This should work: 这应该工作:

<Button 
x:Name="Marker_Detection" 
Text="Marker Detection" 
Grid.Row="0" 
Grid.Column="0" 
Clicked="MarkerDetectionClick" />

You may want to set your debugging settings to break when an exception is thrown, it should give you more information about the real problem when things like this happen. 您可能希望将调试设置设置为在引发异常时中断,这样可以在发生此类情况时为您提供有关实际问题的更多信息。 Here is some info on how to do this in Visual Studio, I assume Xamarin Studio has similar settings if you're using that. 以下是有关如何在Visual Studio中执行此操作的一些信息,如果您使用Xamarin Studio,则假定Xamarin Studio具有类似的设置。

https://msdn.microsoft.com/en-us/library/x85tt0dd.aspx https://msdn.microsoft.com/zh-CN/library/x85tt0dd.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM