【发布时间】:2018-03-20 09:53:46
【问题描述】:
我正在开发一个简单的 Xamarin Form 应用程序。我创建了一个简单的登录内容页面,当我尝试运行 android 模拟器时,我收到此错误“异常已由调用目标引发。”,我在下面提到了我的代码。 .xaml 和 LoginPage.xaml.cs
LoginPage.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="XLoginApplication.Views.LoginPage">
<StackLayout x:Name="MasterLayout">
<StackLayout x:Name="LogoStack" VerticalOptions="FillAndExpand">
<Image x:Name="LoginIcon" Source="icon.png" Margin="0.80.0.0"/>
</StackLayout>
<StackLayout x:Name="LoginEntriesStack" VerticalOptions="StartAndExpand">
<StackLayout.Padding>
<OnIdiom x:TypeArguments ="Thickness">
<OnIdiom.Phone>40,0,40,0</OnIdiom.Phone>
<OnIdiom.Tablet>140,150,140,0</OnIdiom.Tablet>
</OnIdiom>
</StackLayout.Padding>
<ActivityIndicator x:Name="ActivitySpinner" Color="Red" IsRunning="True"></ActivityIndicator>
<Label x:Name="Lbl_Username" Text="Username" />
<Entry x:Name="Entry_Username" Placeholder="Username" />
<Label x:Name="Lbl_Password" Text="Password"/>
<Entry x:Name ="Entry_Password" Placeholder="Password" />
<Button x:Name ="Btn_Signin" Text="Sign In" Clicked="SignInProcedure"/>
</StackLayout>
</StackLayout>
</ContentPage>
LoginPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using XLoginApplication.Models;
namespace XLoginApplication.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LoginPage : ContentPage
{
public LoginPage ()
{
InitializeComponent ();
Init();
}
void Init()
{
BackgroundColor = Constants.BackgroundColor;
Lbl_Username.TextColor = Constants.MainTextColor;
Lbl_Password.TextColor = Constants.MainTextColor;
ActivitySpinner.IsVisible = false;
LoginIcon.HeightRequest = Constants.LoginIconHeight;
Entry_Username.Completed += (s, e) => Entry_Password.Focus();
Entry_Password.Completed += (s, e) => SignInProcedure(s, e);
}
public void SignInProcedure(object sender ,EventArgs e)
{
User user = new User(Entry_Username.Text ,Entry_Password.Text);
if (user.CheckInformation())
{
DisplayAlert("Login", "Login Success", "Oke");
}
else
{
DisplayAlert("Login", "Login Not Suceesfull User name or Password is empty", "Oke");
}
}
}
}
【问题讨论】:
标签: c# xamarin xamarin.forms xamarin.android