我正在尝试使用xamarin.form实现一个loginview。我已经在我的项目中实现了以下代码,但是,一旦我运行,它就不会在视图上显示任何内容。
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") }
}
}
};
}
}
}发布于 2014-11-11 22:16:21
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
}https://stackoverflow.com/questions/26875552
复制相似问题