【发布时间】:2018-06-09 22:37:31
【问题描述】:
我正在使用 Xamrian 表单我遇到一个问题,当我从登录表单调用我的主页时,它会复制工具栏。
在我的 app.xml 中,我正在唱以下内容
public static Page GetMainPage()
{
return new NavigationPage(new MainPage());
//return new ExamplePage ();
}
在有人说这是一个最小的例子之前,我不想显示我所有的登录代码 obv 原因。
void OnLoginButtonClicked(object sender, EventArgs e)
{
var isValid = true;
if (isValid)
{
Application.Current.MainPage = App.GetMainPage();
}
else
{
messageLabel.Text = "Login failed";
passwordEntry.Text = string.Empty;
}
}
Login.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="DeliveryDriver.Views.LoginPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Sign Up" />
</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>
我的主页 xaml。
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:DeliveryDriver.Views"
x:Class="DeliveryDriver.Views.MainPage">
<TabbedPage.Children>
<NavigationPage Title="Jobs">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:JobsPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Items Test">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:ItemsPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="About">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_about.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:AboutPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
按照建议,我将 app.cs 调用更改为登录页面,如下所示。
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage());
}
【问题讨论】:
标签: c# xamarin.forms