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); 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); SetContentProperty(targetLocation, view); ViewModelBinder.Bind(args.NewValue, view, context); } else { SetContentProperty(targetLocation, args.NewValue); } }
/// <summary> /// Creates a window. /// </summary> /// <param name="rootModel">The view model.</param> /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param> /// <param name="context">The view context.</param> /// <returns>The window.</returns> protected virtual Window CreateWindow(object rootModel, bool isDialog, object context) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Window.TitleProperty, binding); } new WindowConductor(rootModel, view); return(view); }