Example #1
0
 static void SetViewModelDocumentOwner(object viewModel, IDocumentOwner documentOwner)
 {
     if (viewModel == null)
     {
         return;
     }
     viewModel.With(x => x as IDocumentContent).Do(x => x.DocumentOwner = documentOwner);
 }
Example #2
0
 public static DocumentOwnerWrapper Create(IDocumentOwner owner)
 {
     if (owner == null)
     {
         return(null);
     }
     return(owner as DocumentOwnerWrapper ?? new DocumentOwnerWrapper(owner));
 }
Example #3
0
        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);
        }
Example #4
0
 public static void SetViewModelDocumentOwner(DependencyObject view, IDocumentOwner documentOwner)
 {
     SetViewModelDocumentOwner(ViewHelper.GetViewModelFromView(view), documentOwner);
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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);
     }
 }
Example #7
0
 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);
            }
        }
Example #9
0
 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);
     }
 }
Example #10
0
 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));
 }
Example #12
0
 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;
 }
Example #13
0
 DocumentOwnerWrapper(IDocumentOwner actualOwner) {
     this.actualOwner = actualOwner;
 }
Example #14
0
 public static DocumentOwnerWrapper Create(IDocumentOwner owner) {
     if(owner == null)
         return null;
     return owner as DocumentOwnerWrapper ?? new DocumentOwnerWrapper(owner);
 }
Example #15
0
 static void OnDocumentOwnerChanged(DependencyObject d, IDocumentOwner newValue)
 {
     SetDocumentOwnerCore(d, newValue);
     ParameterAndParentViewModelSyncBehavior.AttachTo(d);
 }
Example #16
0
        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);
        }
Example #17
0
 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);
 }
Example #19
0
 static void OnDocumentOwnerChanged(DependencyObject d, IDocumentOwner newValue)
 {
     ViewModelInitializer.SetViewModelDocumentOwner(d, newValue);
     ParameterAndParentViewModelSyncBehavior.AttachTo(d);
 }