作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Xamarin.Forms 时遇到了一种我无法解决的奇怪行为。
应用程序的基本流程是登录页面是一个登录表单。登录时,这会将您带到一个选项卡式页面。当我使用注销功能时,它会返回登录页面,但选项卡似乎保留在原位。
登录.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="TechsportiseApp.Login">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="20, 40, 20, 20"
Android="20, 20, 20, 20"
WinPhone="20, 20, 20, 20" />
</ContentPage.Padding>
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Orientation="Vertical"
Spacing="15">
<Label Text="Email" />
<Entry x:Name="email" Text="123@test.com" />
<Label Text="Password" />
<Entry x:Name="password" Text="xxxxxx" IsPassword="true"/>
<Button x:Name="loginButton" Text="Login" Clicked="OnLogin"/>
<Button x:Name="registerButton" Text="Register Account" Clicked="OnRegister"/>
<Button x:Name="clearButton" Text="Reset" Clicked="OnClear"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
如果我从 API 获得登录成功代码,此部分会将它们移至主页。
登录.xaml.cs
//Valid response
if (response.StatusCode.ToString() == "OK")
{
Application.Current.Properties["Token"] = tokenobject.access_token;
string token = Application.Current.Properties["Token"].ToString();
Navigation.InsertPageBefore (new MainPage (), this);
await Navigation.PopAsync();
}
MainPage.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:local="clr-namespace:TechsportiseApp.MainUI"
x:Class="TechsportiseApp.MainUI.MainPage">
<local:Races />
<local:Timer />
<local:Scanning />
<NavigationPage Title="Settings">
<x:Arguments>
<local:Settings />
</x:Arguments>
</NavigationPage>
</TabbedPage>
里面的每一个页面都是Valid。设置页面有一个注销按钮。
Settings.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="TechsportiseApp.MainUI.Settings"
Title="Settings">
<ContentPage.Content>
<StackLayout>
<Label Text="Settings will go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
<Button x:Name="logoutButton" Text="Logout" Clicked="OnLogout" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
使用 Settings.xaml.cs 中的注销按钮执行此操作
async void OnLogout(object sender, EventArgs e)
{
Application.Current.Properties["Token"] = "";
Navigation.InsertPageBefore (new Login(), this);
await Navigation.PopAsync();
}
但最终结果是我有登录屏幕...底部有标签栏
我做错了什么?我希望这样当我注销时标签页不可见。
谢谢,马特
最佳答案
设置新的 MainPage 就完成了这项工作。在登录和注销时,我使用
为应用程序设置了新的 MainPageApp.Current.MainPage = new NavigationPage(new MainPage())
代替 PopAsync/PushAsync。
关于c# - Xamarin.Forms 选项卡式页面和注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46079404/
我是一名优秀的程序员,十分优秀!