查看代码,LoginPageCS.cs看起来与LoginPage.xaml基本相同 - 所以这将是一种在C#中创建页面控件的方式,而不是XAML。有关差异的讨论,请参阅this question。
注意的相似
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="LoginNavigation.LoginPage" Title="Login">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Sign Up" Clicked="OnSignUpButtonClicked" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout VerticalOptions="StartAndExpand">
<Label Text="Username" />
<Entry x:Name="usernameEntry" Placeholder="username" />
<Label Text="Password" />
<Entry x:Name="passwordEntry" IsPassword="true" />
<Button Text="Login" Clicked="OnLoginButtonClicked" />
<Label x:Name="messageLabel" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
LoginPageCS.cs:
public LoginPageCS()
{
var toolbarItem = new ToolbarItem {
Text = "Sign Up"
};
toolbarItem.Clicked += OnSignUpButtonClicked;
ToolbarItems.Add (toolbarItem);
messageLabel = new Label();
usernameEntry = new Entry {
Placeholder = "username"
};
passwordEntry = new Entry {
IsPassword = true
};
var loginButton = new Button {
Text = "Login"
};
loginButton.Clicked += OnLoginButtonClicked;
Title = "Login";
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Children = {
new Label { Text = "Username" },
usernameEntry,
new Label { Text = "Password" },
passwordEntry,
loginButton,
messageLabel
}
};
}
保证金只是一种直观的方式告诉页面通过C#代码中创建和不是Xaml。 – SushiHangover
XAML对UI设计师很友善,并且是*代码生成器*的输入。您通常无法看到它生成的代码,并且代码不太漂亮。所以作为替代方案,他们还提供了fooCS.cs文件,它与foo.xaml和foo.xaml.cs文件完全相同。但在另一个名为fooCS的类中。该类实际上并未在项目中使用。除了示范使用之外,它可能会激发程序员编写代码而不是xaml。 –