static void SetViewModelDocumentOwner(object viewModel, IDocumentOwner documentOwner) { if (viewModel == null) { return; } viewModel.With(x => x as IDocumentContent).Do(x => x.DocumentOwner = documentOwner); }
public static DocumentOwnerWrapper Create(IDocumentOwner owner) { if (owner == null) { return(null); } return(owner as DocumentOwnerWrapper ?? new DocumentOwnerWrapper(owner)); }
public static void InitializeView(object view, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner = null) { if(documentOwner is DependencyObject) documentOwner = DocumentOwnerWrapper.Create(documentOwner); if(viewModel != null) { if(parameter != null) viewModel.With(x => x as ISupportParameter).Do(x => x.Parameter = parameter); if(parentViewModel != null) viewModel.With(x => x as ISupportParentViewModel).Do(x => x.ParentViewModel = parentViewModel); if(documentOwner != null) viewModel.With(x => x as IDocumentContent).Do(x => x.DocumentOwner = documentOwner); view.With(x => x as FrameworkElement).Do(x => x.DataContext = viewModel); view.With(x => x as ContentPresenter).Do(x => x.Content = viewModel); return; } if(!(view is DependencyObject)) return; if(ViewModelExtensions.NotSetParameter == ViewModelExtensions.GetParameter((DependencyObject)view) || parameter != null) ViewModelExtensions.SetParameter((DependencyObject)view, parameter); if(ViewModelExtensions.GetParentViewModel((DependencyObject)view) == null || parentViewModel != null) ViewModelExtensions.SetParentViewModel((DependencyObject)view, parentViewModel); if(ViewModelExtensions.GetDocumentOwner((DependencyObject)view) == null || documentOwner != null) ViewModelExtensions.SetDocumentOwner((DependencyObject)view, documentOwner); }
public static void SetViewModelDocumentOwner(DependencyObject view, IDocumentOwner documentOwner) { SetViewModelDocumentOwner(ViewHelper.GetViewModelFromView(view), documentOwner); }
public static void SetViewModelProperties(object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner) { if (viewModel == null) { return; } if (parameter != null) { SetViewModelParameter(viewModel, parameter); } if (parentViewModel != null) { SetViewModelParentViewModel(viewModel, parentViewModel); } if (documentOwner != null) { SetViewModelDocumentOwner(viewModel, documentOwner); } }
public static void SetViewModelProperties(DependencyObject view, object parameter, object parentViewModel, IDocumentOwner documentOwner) { if (view == null) { return; } if (ViewModelExtensions.NotSetParameter == ViewModelExtensions.GetParameter(view) || parameter != null) { ViewModelExtensions.SetParameter(view, parameter); } if (ViewModelExtensions.GetParentViewModel(view) == null || parentViewModel != null) { ViewModelExtensions.SetParentViewModel(view, parentViewModel); } if (ViewModelExtensions.GetDocumentOwner(view) == null || documentOwner != null) { ViewModelExtensions.SetDocumentOwner(view, documentOwner); } }
DocumentOwnerWrapper(IDocumentOwner actualOwner) { this.actualOwner = actualOwner; }
public static void InitializeView(object view, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner = null) { if (documentOwner is DependencyObject) { documentOwner = DocumentOwnerWrapper.Create(documentOwner); } if (viewModel != null) { if (parameter != null) { viewModel.With(x => x as ISupportParameter).Do(x => x.Parameter = parameter); } if (parentViewModel != null) { viewModel.With(x => x as ISupportParentViewModel).Do(x => x.ParentViewModel = parentViewModel); } if (documentOwner != null) { viewModel.With(x => x as IDocumentContent).Do(x => x.DocumentOwner = documentOwner); } view.With(x => x as FrameworkElement).Do(x => x.DataContext = viewModel); view.With(x => x as ContentPresenter).Do(x => x.Content = viewModel); return; } if (!(view is DependencyObject)) { return; } if (ViewModelExtensions.NotSetParameter == ViewModelExtensions.GetParameter((DependencyObject)view) || parameter != null) { ViewModelExtensions.SetParameter((DependencyObject)view, parameter); } if (ViewModelExtensions.GetParentViewModel((DependencyObject)view) == null || parentViewModel != null) { ViewModelExtensions.SetParentViewModel((DependencyObject)view, parentViewModel); } if (ViewModelExtensions.GetDocumentOwner((DependencyObject)view) == null || documentOwner != null) { ViewModelExtensions.SetDocumentOwner((DependencyObject)view, documentOwner); } }
public static void InitializeView(object view, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner = null) { if (documentOwner is DependencyObject) { documentOwner = DocumentOwnerWrapper.Create(documentOwner); } if (viewModel != null) { ViewModelInitializer.SetViewModelProperties(viewModel, parameter, parentViewModel, documentOwner); view.With(x => x as FrameworkElement).Do(x => x.DataContext = viewModel); view.With(x => x as FrameworkContentElement).Do(x => x.DataContext = viewModel); view.With(x => x as ContentPresenter).Do(x => x.Content = viewModel); return; } if (view is DependencyObject) { ViewModelInitializer.SetViewModelProperties((DependencyObject)view, parameter, parentViewModel, documentOwner); } }
public static void SetDocumentOwner(DependencyObject obj, IDocumentOwner value) { obj.SetValue(DocumentOwnerProperty, value); }
protected object CreateAndInitializeView(string documentType, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner = null) { return(ViewHelper.CreateAndInitializeView(ViewLocator, documentType, viewModel, parameter, parentViewModel, documentOwner, ViewTemplate, ViewTemplateSelector)); }
public static object CreateAndInitializeView(IViewLocator viewLocator, string documentType, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner, DataTemplate viewTemplate = null, DataTemplateSelector viewTemplateSelector = null) { object view = CreateView(viewLocator, documentType, viewTemplate, viewTemplateSelector); InitializeView(view, viewModel, parameter, parentViewModel, documentOwner); return view; }
public static DocumentOwnerWrapper Create(IDocumentOwner owner) { if(owner == null) return null; return owner as DocumentOwnerWrapper ?? new DocumentOwnerWrapper(owner); }
static void OnDocumentOwnerChanged(DependencyObject d, IDocumentOwner newValue) { SetDocumentOwnerCore(d, newValue); ParameterAndParentViewModelSyncBehavior.AttachTo(d); }
public static object CreateAndInitializeView(IViewLocator viewLocator, string documentType, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner, DataTemplate viewTemplate = null, DataTemplateSelector viewTemplateSelector = null) { object view = CreateView(viewLocator, documentType, viewTemplate, viewTemplateSelector); InitializeView(view, viewModel, parameter, parentViewModel, documentOwner); return(view); }
static void SetDocumentOwnerCore(DependencyObject d, IDocumentOwner documentOwner) { ViewHelper.GetViewModelFromView(d).With(x => x as IDocumentContent).Do(x => x.DocumentOwner = documentOwner); }
protected object CreateAndInitializeView(string documentType, object viewModel, object parameter, object parentViewModel, IDocumentOwner documentOwner = null) { return ViewHelper.CreateAndInitializeView(ViewLocator, documentType, viewModel, parameter, parentViewModel, documentOwner, ViewTemplate, ViewTemplateSelector); }
static void OnDocumentOwnerChanged(DependencyObject d, IDocumentOwner newValue) { ViewModelInitializer.SetViewModelDocumentOwner(d, newValue); ParameterAndParentViewModelSyncBehavior.AttachTo(d); }