Xamarin Forms和Visual Studio中的异常 - 发生了未处理的异常

时间:2017-04-24 19:45:05

标签: c# android xamarin xamarin.forms visual-studio-2017

我正在使用Visual Studio 2017在Xamarin Forms中开发应用程序。 到目前为止,我还没有遇到任何重大问题,但现在当我在Android设备上调试我的应用程序时,它总是返回一个try / catch未检测到的异常。 除了这些之外,IDE中没有太多关于这个事实的信息: 1 - 发生未处理的异常。 2 - 所选的调试机制不支持在当前线程上运行的任何代码(例如,只运行本机运行时代码) 当我尝试导航到用户需要输入验证码的注册确认屏幕时,总会发生错误。 "搞笑"就是当我在模拟器上执行相同的过程时,没有发生这种情况。 可能发生了什么以及纠正问题需要什么?

以下是屏幕上的例外情况。 enter image description here 这是确认页面的代码。

// --- --- XAML \

    <?xml version="1.0" encoding="utf-8" ?>``
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FlipDigital.Views.FlipDigital_ConfirmarCadastro"
             Title="Confirmar Cadastro">
    <AbsoluteLayout>

        <!--#region Imagem de Background-->

        <Image x:Name="imgBackground" Aspect="AspectFill"
                Source="https://sites.google.com/site/clickemenow/arquivos/Background.png?attredirects=0"
                AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All"
                />

        <!--#endregion-->

        <!--#region Imagem Agencia-->

        <Image x:Name="imgAgencia"
            Source="logoflipdigital.png"
            WidthRequest="150"
            HeightRequest="150"
            BackgroundColor="Transparent"
            AbsoluteLayout.LayoutBounds=".5,0,.4,.3" AbsoluteLayout.LayoutFlags="All"
        />

        <Label BackgroundColor="Transparent"
                    Text="Flip Digital" FontSize="22" TextColor="White"
                    x:Name="lbTitulo"
                    Opacity="0.9"
                    HeightRequest="60"
                    WidthRequest="50"
                    VerticalTextAlignment="Center"
                    HorizontalTextAlignment="Center"
                    AbsoluteLayout.LayoutBounds=".5,.3,.8,.1" AbsoluteLayout.LayoutFlags="All"
               />

        <Label BackgroundColor="Transparent"
                    Text="Sua Agência OnLine" FontSize="16" TextColor="White"
                    x:Name="lbSubtitulo"
                    Opacity="0.9"
                    HeightRequest="60"
                    WidthRequest="50"
                    VerticalTextAlignment="Center"
                    HorizontalTextAlignment="Center"
                    AbsoluteLayout.LayoutBounds=".5,.35,.8,.1" AbsoluteLayout.LayoutFlags="All"
               />

        <Entry BackgroundColor="White"
                    FontSize="18"
                    x:Name="txtCodVerificacao"
                    Placeholder="Codigo Veficador"
                    Opacity="0.6"
                    HorizontalTextAlignment="Center"
                    HeightRequest="60"
                    WidthRequest="50"
                    AbsoluteLayout.LayoutBounds=".5,.5,.88,.1" AbsoluteLayout.LayoutFlags="All"
               />

        <!--#endregion-->

        <!--#region Bloco Cadastrar e Nova Senha-->

        <Button BackgroundColor="Teal"
                    x:Name="btnReenviar"
                    Text="Reenviar código" FontSize="15"
                    TextColor="White" Opacity="0.8"
                    HeightRequest="60"
                    WidthRequest="50"
                    AbsoluteLayout.LayoutBounds=".1,.65,.4,.1" AbsoluteLayout.LayoutFlags="All"
               />

        <Button BackgroundColor="Teal"
                    x:Name="btnConfirmar"
                    Text="Verificar código" FontSize="15"
                    TextColor="White" Opacity="0.8"
                    HeightRequest="60"
                    WidthRequest="50"
                    AbsoluteLayout.LayoutBounds=".9,.65,.4,.1" AbsoluteLayout.LayoutFlags="All"
               />
        <!--#endregion-->

    </AbsoluteLayout>
</ContentPage>

// --- C#--- \

namespace FlipDigital.Views
{

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class FlipDigital_ConfirmarCadastro : ContentPage
    {

        public bool Agencia { get; set; }

        public FlipDigital_ConfirmarCadastro(bool agencia)
        {
            try
            {
                InitializeComponent();
                this.Agencia = agencia;
                btnConfirmar.Clicked += Seguir;
                //BindingContext = new ContentPageViewModel();
            }
            catch (Exception ex)
            {
                DisplayAlert("Exception", ex.Message, "OK");
            }
        }

        private async void ReenviarCodigo(object sender, EventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                await DisplayAlert("Exception", ex.Message, "OK");
            }
        }

        private async void Seguir(object sender, EventArgs e)
        {
            try
            {
                await DisplayAlert("Alert", "Cadastro confirmado com sucesso. Você está sendo direcionado a pagina inicial do app.", "OK");

                if (Agencia)
                {
                    await Navigation.PushAsync(new FlipDigital_InicialAgencia());
                }
                else
                {
                    await Navigation.PushAsync(new FlipDigital_InicialCliente());
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Exception", ex.Message, "OK");
            }
        }
    }

    class FlipDigital_ConfirmarCadastroViewModel : INotifyPropertyChanged
    {

        public FlipDigital_ConfirmarCadastroViewModel()
        {
            IncreaseCountCommand = new Command(IncreaseCount);
        }

        int count;

        string countDisplay = "You clicked 0 times.";
        public string CountDisplay
        {
            get { return countDisplay; }
            set { countDisplay = value; OnPropertyChanged(); }
        }

        public ICommand IncreaseCountCommand { get; }

        void IncreaseCount() =>
            CountDisplay = $"You clicked {++count} times";


        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName]string propertyName = "") =>
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    }
}

值得一提的是,异常仅发生在此页面中,因为其他页面的导航正常发生。

0 个答案:

没有答案