Pass parámetro de datos del modelo a la página siguiente Prism Xamarin Forms
Necesito pasar datos de ViewModel 1 a ViewModel 2 usando Prism.
TodoItem
es mi modelo con la cadena:
public TodoItem _todotItem { get; set; }
private readonly INavigationService _navigationService;
Lo asigné en el constructor:
public MainPageViewModel(INavigationService navigationService, TodoItem todotItem)
{
_navigationService = navigationService;
_todotItem = todotItem;
}
Y este es el código que uso para navegar a la página siguiente (incluido el parámetro):
NavigationParameters navParams = new NavigationParameters();
navParams.Add("PassedValue", _todoItem.name);
_navigationService.NavigateAsync("SecondPage", navParams);
Cuando configuro el punto de interrupción en_todoItem.name
dicenul. Los datos se obtienen antes de hacer clic enlistview
. ¿Qué me estoy perdiendo
Editar
Así es como navego (haga clic enlistview
):
private EventItem _selectedEvent { get; set; }
public EventItem SelectedEvent
{
get { return _selectedEvent; }
set
{
if (_selectedEvent != value)
{
if (Device.RuntimePlatform == Device.iOS)
{
_selectedEvent = null;
}
else
{
_selectedEvent = value;
}
NavigationParameters navParams = new NavigationParameters();
navParams.Add("PassedValue", _todoItem.name);
_navigationService.NavigateAsync("SecondPage", navParams);
}
}
}
Utilizo las formas correctas de capturar el parámetro en la segundaViewModel
(Sin embargo, obtengonul en el primeroViewModel
):
public void OnNavigatingTo(INavigationParameters parameters)
{
if (parameters.ContainsKey("PassedValue"))
{
_todo = (string)parameters["PassedValue"];
OnPropertyChanged("Todo");
}
}
Yo sueloHTTPClient
para obtener datos.