Xamarin.Form中的LoginView
我正在尝试使用xamarin.form实现loginview。我已经在我的项目中实现了以下代码,但是,一旦我运行,它就不会在视图上显示任何内容Xamarin.Form中的LoginView,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我正在尝试使用xamarin.form实现loginview。我已经在我的项目中实现了以下代码,但是,一旦我运行,它就不会在视图上显示任何内容 using System; using System.Collections.Generic; using Xamarin.Forms; namespace WebComponents { public partial class LoginView : ContentPage { public LoginV
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace WebComponents
{
public partial class LoginView : ContentPage
{
public LoginView ()
{
InitializeComponent ();
var profilePage = new ContentPage {
Title = "Profile",
Content = new StackLayout {
Spacing = 20,
Padding = 50,
VerticalOptions = LayoutOptions.Center,
Children = {
new Entry { Placeholder = "Username" },
new Entry { Placeholder = "Password", IsPassword = true },
new Button { Text = "Login", TextColor = Color.White, BackgroundColor = Color.FromHex("77D065") }
}
}
};
}
}
}
LoginView是ContentPage的一个子类-您正在创建另一个ContentPage,profilePage,但没有对其执行任何操作。请尝试以下方法:
Entry username;
Entry password;
Button button;
public LoginView ()
{
InitializeComponent ();
Title = "Profile";
Content = new StackLayout {
Spacing = 20,
Padding = 50,
VerticalOptions = LayoutOptions.Center,
Children = {
(username = new Entry { Placeholder = "Username" }),
(password = new Entry { Placeholder = "Password", IsPassword = true }),
(button = new Button { Text = "Login", TextColor = Color.White, BackgroundColor = Color.FromHex("77D065") })
}
}
};
button.Clicked += Login;
}
public void Login(object sender, EventArgs ea)
{
// check values of username and password here
}
@杰森,非常感谢,很有效。一旦SOF允许,我会在几分钟内标记您的答案。在这种情况下,我们如何检查用户名和密码?非常感谢。如何在应用程序输出上写入用户名?Console.WriteLine不工作。Console.WriteLine(用户名);Nevermind,System.Diagnostics.Debug.WriteLine(用户名);显然,您不能在初始值设定项中分配事件处理程序。查看我的新编辑。