/// <summary> /// Occurs after navigation /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnNavigated(object sender, NavigationEventArgs e) { if (e.Uri.IsAbsoluteUri) { return; } ViewLocator.InitializeComponent(e.Content); var viewModel = ViewModelLocator.LocateForView(e.Content); if (viewModel == null) { return; } ViewModelBinder.Bind(viewModel, (DependencyObject)e.Content, null); TryInjectQueryString(viewModel, e.Content); var activator = viewModel as IActivate; if (activator != null) { activator.Activate(); } }
static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (Bootstrapper.IsInDesignMode || e.NewValue == null || e.NewValue == e.OldValue) { return; } var fe = d as FrameworkElement; if (fe == null) { return; } RoutedEventHandler handler = null; handler = delegate { var target = e.NewValue; var containerKey = e.NewValue as string; if (containerKey != null) { target = IoC.GetInstance(null, containerKey); } d.SetValue(View.IsLoadedProperty, true); ViewModelBinder.Bind(target, d, null); fe.Loaded -= handler; }; fe.Loaded += handler; }
private 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); ViewModelBinder.Bind(model, view, e.NewValue); SetContentProperty(targetLocation, view); }
private 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); SetContentProperty(targetLocation, view); } else { SetContentProperty(targetLocation, args.NewValue); } }