2017-01-16 119 views
0

在ContentPage中,我有一個ListView中的「房間」列表。當我點擊其中一個時,它應該導航到另一個ContentPage與房間的細節。新頁面的ViewModel上的OnNavigatedTo()被調用(顯然沒有錯誤),但該頁面未顯示。它留在房間列表的頁面上。Xamarin形成棱鏡 - 從網格導航到內容頁面。頁面未顯示

<?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> 

這裏的視圖模型的一個片段:

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"); 
} 

細節我與Visual Studio 2015年

這裏列表頁面的XAML與Android(仿真器和手機)進行測試頁:

<?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> 

視圖模型的一個片段:

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

回答

1

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

+0

它已註冊。如果在OnInitialized()我把:NavigationService.NavigateAsync(「RoomDetail」);該頁面出現。 – Alberto

+0

然後,RoomsList頁面可能有問題。嘗試將TapGesture放置在ListView上而不是StackPanel上。 –

+0

也許你是對的。如果我把眼前這個列表頁: