static void OnContextChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs e) { if (e.OldValue == e.NewValue) { return; } var model = GetModel(targetLocation); if (model == null) { return; } var view = ViewLocator.LocateForModel(model, targetLocation, e.NewValue); if (!SetContentProperty(targetLocation, view)) { Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType"); view = ViewLocator.LocateForModelType(model.GetType(), targetLocation, e.NewValue); SetContentProperty(targetLocation, view); } ViewModelBinder.Bind(model, view, e.NewValue); }
static void OnModelChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args) { if (args.OldValue == args.NewValue) { return; } if (args.NewValue != null) { var context = GetContext(targetLocation); var view = ViewLocator.LocateForModel(args.NewValue, targetLocation, context); ViewModelBinder.Bind(args.NewValue, view, context); if (!SetContentProperty(targetLocation, view)) { Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType"); view = ViewLocator.LocateForModelType(args.NewValue.GetType(), targetLocation, context); SetContentProperty(targetLocation, view); } } else { SetContentProperty(targetLocation, args.NewValue); } }
/// <summary> /// A task for asynchronously pushing a view for the given view model onto the navigation stack, with optional animation. /// </summary> /// <param name="viewModelType">The type of the view model</param> /// <param name="parameter">The paramter to pass to the view model</param> /// <param name="animated">Animate the transition</param> /// <returns>The asynchrous task representing the transition</returns> public Task NavigateToViewModelAsync(Type viewModelType, object parameter = null, bool animated = true) { if (!CanClose()) { return(Task.FromResult(false)); } var view = ViewLocator.LocateForModelType(viewModelType, null, null); return(PushAsync(view, parameter, animated)); }
/// <summary> /// A task for asynchronously pushing a view for the given view model onto the navigation stack, with optional animation. /// </summary> /// <param name="viewModelType">The type of the view model</param> /// <param name="parameter">The paramter to pass to the view model</param> /// <param name="animated">Animate the transition</param> /// <returns>The asynchrous task representing the transition</returns> public async Task NavigateToViewModelAsync(Type viewModelType, object parameter = null, bool animated = true) { var canClose = await CanCloseAsync(); if (!canClose) { return; } var view = ViewLocator.LocateForModelType(viewModelType, null, null); await PushAsync(view, parameter, animated); }