首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >知道为什么"GoToAsync“在AppShell.cs中不起作用吗?

知道为什么"GoToAsync“在AppShell.cs中不起作用吗?
EN

Stack Overflow用户
提问于 2021-09-17 14:02:26
回答 1查看 300关注 0票数 0

注册详细页路由

AppShell.cs

代码语言:javascript
复制
public partial class AppShell : Xamarin.Forms.Shell
    {
        public AppShell(string message)
        {
            InitializeComponent();
            Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage));
            Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage));
            Routing.RegisterRoute("LoginPage", typeof(LoginPage));
if (message != "main") {
                
                
                int itemid = Int32.Parse(message);
                var item = App.Database.GetItemAsyncId(itemid).Result;
                var itemValue = new Models.Item
                {
                    Id = item.Id,
                    Description = item.Description,
                    Text = item.Text
                };
                OnItemSelected(itemValue);
                   }
    }
         public async void OnItemSelected(Item item)
        {  
         await Shell.Current.GoToAsync("LoginPage");
       //Shell.Current.GoToAsync($"{nameof(ItemDetailPage)}?{nameof(ItemDetailViewModel.ItemId)}={item.Id}");
      
        }}

当我在模拟器上启动应用程序时,应用程序应该启动页面:

starts;

  • "LoginPage“-
  1. "AboutPage”--它没有开始。"LoginPage“应该使用LoginPage加载

编辑器不会显示错误。

是navigationStack

代码语言:javascript
复制
    <FlyoutItem x:Name="ItemsPage" Icon="icon_feed.png">
        <ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
    </FlyoutItem>
    <FlyoutItem x:Name="About" Icon="icon_about.png">
        <ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
    </FlyoutItem>
    

    <!-- When the Flyout is visible this will be a menu item you can tie a click behavior to  -->
    <MenuItem Text="Logout" StyleClass="MenuItemLayoutStyle" Clicked="OnMenuItemClicked">
    </MenuItem>

    <!--
        TabBar lets you define content that won't show up in a flyout menu. When this content is active
        the flyout menu won't be available. This is useful for creating areas of the application where 
        you don't want users to be able to navigate away from. If you would like to navigate to this 
        content you can do so by calling 
        await Shell.Current.GoToAsync("//LoginPage");
    -->
    <TabBar>
        <ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
    </TabBar>
EN

回答 1

Stack Overflow用户

发布于 2021-09-17 15:38:55

你的方法被调用了吗?消息变量的值是多少?检查if (message != "main")是否为真,有时它只发生在构造函数上。

编辑

要在构造函数中导航Shell页面,必须用"Shell.Current.GoToAsync('LoginPage')"替换"this.GoToAsync('LoginPage')"

在实例的时刻,创建的Shell不是应用程序的“当前”外壳。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69224735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档