【发布时间】:2017-01-17 02:40:06
【问题描述】:
在 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 的 sn-p:
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 的 sn-p:
public void OnNavigatedTo(NavigationParameters parameters)
{
// on Debug I enter in this method!
}
【问题讨论】:
标签: c# xamarin.forms prism