让弹出菜单按照我想要的方式在 Xamarin Forms 中工作一直是一个很大的痛苦。我试图让某个菜单项(我的统计信息)在用户登录时转到某个页面,或者在用户未登录时转到另一个页面(登录页面)。我尝试了两种不同的方法但没有成功。
首先,我尝试在 XAML 中使用 Shell Content 中的指定路径设置弹出项目,如下所示:
<FlyoutItem Title="My Stats" Icon="icon_feed.png">
<ShellContent x:Name="shellContent_myStats" Route="MyStatsPage" ContentTemplate="{DataTemplate local:MyStatsPage}" />
</FlyoutItem>
Run Code Online (Sandbox Code Playgroud)
然后,当用户登录/注销时,我会以编程方式修改路由:
//Logging Out
shellContent_myStats.ContentTemplate = new DataTemplate(typeof(LoginPage));
Routing.SetRoute(shellContent_myStats, "LoginPage");
...
//Logging In
shellContent_myStats.ContentTemplate = new DataTemplate(typeof(MyStatsPage));
Routing.SetRoute(shellContent_myStats, "MyStatsPage");
Run Code Online (Sandbox Code Playgroud)
我无法让它发挥作用。无论出于何种原因,只有第一个被执行的部分才会生效。例如,如果我在注销时启动应用程序,它会按预期定向到登录页面,但在我注销后不会切换。反之亦然,如果我在登录时启动应用程序,它会按预期导航到“我的统计”页面,但即使在我注销后也会继续这样做。
我尝试了上述代码的几种不同变体,但均无济于事。
我尝试的第二种方法是使用 OnClick 事件处理程序在 XAML 中指定菜单项,如下所示:
<MenuItem Text="My Journey" StyleClass="MenuItemLayoutStyle" Clicked="OnMyStatsClicked"/>
Run Code Online (Sandbox Code Playgroud)
背后代码:
public AppShell()
{
//Route now needs to be registered in page constructor
Routing.RegisterRoute(nameof(MyStatsPage), typeof(MyStatsPage));
...
public async void OnMyStatsClicked(object sender, EventArgs e)
{
Shell.Current.FlyoutIsPresented = false; …Run Code Online (Sandbox Code Playgroud) 嘿,所以我在添加注释之前使用了这个Java程序,但是现在我收到了一个错误,其中if和else语句说他们没有if,这些注释是否干扰了如何读取if语句?任何帮助深表感谢.
/**
* A class that takes 2 different times in military time as input and
* outputs the difference in hours and minutes.
*
* @author Name
*/
import java.util.Scanner;
public class Assignment1Q3
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter the first time: ");
int fTime = in.nextInt();
System.out.print("Please enter the second time: ");
int lTime = in.nextInt();
int tDifference = Math.abs(fTime - lTime);//Calculates the absolute difference.
String strTDiff = String.valueOf(tDifference);//Converts the …Run Code Online (Sandbox Code Playgroud)