0
ContentPageでは、ListViewに「rooms」のリストがあります。そのうちの1つをクリックすると、部屋の詳細を含む別の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>
の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");
}
詳細私は、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>
のViewModelの抜粋:
public void OnNavigatedTo(NavigationParameters parameters)
{
// on Debug I enter in this method!
}
登録されています。 OnInitialized()の場合、次のように指定します。NavigationService.NavigateAsync( "RoomDetail");ページが表示されます。 – Alberto
ルームリストのページに問題がある可能性があります。 TapGestureをStackPanelではなくListViewに配置してみてください。 –
おそらくあなたは正しいです。私は、リストページにちょうどこれを置く場合: TapGestureRecognizer> StackLayout.GestureRecognizers> StackLayout> これは機能しています。 リストビューの要素からコマンドをリンクする別の方法をご存知ですか?私が知っている唯一の選択肢は、醜いイベントハンドラですが、それはMVVMを破ります。ありがとう! (プリズムは素晴らしいです!) –
Alberto