Xamarin Prism无法导航到新页面

时间:2020-07-02 05:19:01

标签: c# xamarin

当我尝试打开以下页面时,它只是冻结。我已删除页面上的所有内容,但仍然会发生!!!!我不知道发生了什么事。

查看模式

public class selectedIngredientViewModel : BaseViewModel
{
    
    INavigationService _navigationService;

  

    public selectedIngredientViewModel(INavigationService navigationService)
    {



        _navigationService = navigationService;

        
    }



}

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"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         x:Class="RecipeDatabaseXamarin.Views.ingredientListPage"
          NavigationPage.HasNavigationBar="False">

<StackLayout Padding="10" VerticalOptions="FillAndExpand">

    
    <Label x:Name="lblIngredientName" Text="Name:" FontAttributes="Bold" FontSize="22" Margin="10" HorizontalTextAlignment="Left"/>

</StackLayout>

致电此页面

_navigationService.NavigateAsync("selectedIngredientPage");

1 个答案:

答案 0 :(得分:0)

您很有可能只需要await

await _navigationService.NavigateAsync("selectedIngredientPage");

如果您来自另一个线程,则可能需要编组回到主线程(仅当您在另一个线程上时)

Device.BeginInvokeOnMainThread(() => {
    await NavigationService.NavigateAsync("selectedIngredientPage");
});

还需要确保您已正确注册

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterForNavigation<SelectedIngredientPage>();
}

进一步阅读