static void OnParameterChanged(DependencyObject d, object newValue) { if (NotSetParameter == newValue) { return; } ViewModelInitializer.SetViewModelParameter(d, newValue); ParameterAndParentViewModelSyncBehavior.AttachTo(d); }
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); } }
static void OnDocumentOwnerChanged(DependencyObject d, IDocumentOwner newValue) { ViewModelInitializer.SetViewModelDocumentOwner(d, newValue); ParameterAndParentViewModelSyncBehavior.AttachTo(d); }
static void OnParentViewModelChanged(DependencyObject d, object newValue) { ViewModelInitializer.SetViewModelParentViewModel(d, newValue); ParameterAndParentViewModelSyncBehavior.AttachTo(d); }
void OnAssociatedObjectDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { ViewModelInitializer.SetViewModelParameter(AssociatedObject, GetParameter(AssociatedObject)); ViewModelInitializer.SetViewModelParentViewModel(AssociatedObject, GetParentViewModel(AssociatedObject)); ViewModelInitializer.SetViewModelDocumentOwner(AssociatedObject, GetDocumentOwner(AssociatedObject)); }