我面对的是OnNavigatedTo在Prism中的奇怪行为。它总是在Android上运行,但在iOS上它不适用于其中一个页面。见代码:
private void OnSpecialtyTapped()
{
_navigationService.NavigateAsync($"{nameof(SpecialtyFilterPage)}", useModalNavigation: false);
}
private void OnLocationTapped()
{
_navigationService.NavigateAsync($"{nameof(PlacesFilterPage)}", useModalNavigation: false);
}
private void OnTakeChosenSpecialties()
{
var parameters = new NavigationParameters
{
//{"ChosenSpecialtiesIds", CheckedSpecialties.Select(s => s.Id).ToList()}
};
_navigationService.GoBackAsync(parameters);
}
private void OnTakeChosenPlaces()
{
var parameters = new NavigationParameters
{
//{"ChosenPlaces", CheckedPlaces.Select( p => new Models.PlaceParameter {Id=p.Id, Type=Convert.ToString(p.Type)}).ToList()}
};
_navigationService.GoBackAsync(parameters);
}
public void OnNavigatedTo(NavigationParameters parameters)
{
if ( parameters.ContainsKey("ChosenSpecialtiesIds") )
{
var chosenSpecialtiestIds = parameters["ChosenSpecialtiesIds"] as List<string>;
if ( chosenSpecialtiestIds == null ) return;
_filter.Services.Clear();
foreach ( var specialtiestId in chosenSpecialtiestIds )
{
_filter.Services.Add(new ServiceParameter { Id = specialtiestId });
}
}
else if ( parameters.ContainsKey("ChosenPlaces") )
{
var chosenPlaces = parameters["ChosenPlaces"] as List<PlaceParameter>;
if ( chosenPlaces == null ) return;
_filter.Places.Clear();
_filter.Places = chosenPlaces;
}
}
它适用于Specialty,不适用于带有Places的iOS。我正在使用Prism 6.2.0和Xamarin.Forms 2.3.3.193。由于某些错误,我无法使用更新的版本。