簡體   English   中英

Xamarin形成Prism-從網格導航到內容頁面。 頁面未顯示

[英]Xamarin forms Prism - Navigation from grid to content page. Page not shown

在ContentPage中,我在ListView中有一個“房間”列表。 當我單擊其中的一個時,它應導航到包含房間詳細信息的另一個ContentPage。 調用了新頁面的ViewModel上的OnNavigatedTo()(顯然沒有錯誤),但是該頁面沒有顯示。 它留在房間列表的頁面中。 我在Visual Studio 2015上使用Android(模擬器和電話)對其進行了測試。

這是列表頁面的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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:views="clr-namespace:StudentRooms.Views;assembly=StudentRooms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="StudentRooms.Views.RoomsList">

  <StackLayout Orientation="Vertical">
    <ListView ItemsSource="{Binding Rooms}"
              >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout Orientation="Horizontal" Spacing="10">

              <StackLayout.GestureRecognizers>
                <TapGestureRecognizer CommandParameter="{Binding Id}" 
                                      Command="{Binding BindingContext.RoomSelected, Source={views:RoomsList}}">
                </TapGestureRecognizer>
              </StackLayout.GestureRecognizers>

              <Label Text="{Binding Name}" FontAttributes="Bold"/>
              <Label Text="{Binding Description}"></Label>
              <ProgressBar Progress="{Binding Occupancy}"/>
            </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>  
  </StackLayout>

</ContentPage>

這是ViewModel的一個片段:

public RoomsListViewModel(INavigationService navigationService)
{
    _navigationService = navigationService;

    RoomSelected = new DelegateCommand<object>(NavigateToSelectedRoom);
}

private void NavigateToSelectedRoom(object id)
{
    //var navParams = new NavigationParameters
    //{
    //    { "RoomId", id }
    //};

    //_navigationService.NavigateAsync("RoomDetail", navParams);

    _navigationService.NavigateAsync("RoomDetail");
}

詳細信息頁面:

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="StudentRooms.Views.RoomDetail">

  <StackLayout>
    <Label Text="AAA"></Label>
  </StackLayout>
</ContentPage>

ViewModel的一個片段:

public void OnNavigatedTo(NavigationParameters parameters)
{
    // on Debug I enter in this method!
}

確保在App.cs / App.xaml.cs文件中注冊要導航的頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM