/// <summary> /// Subscribes to the parent view model container. /// </summary> private void SubscribeToParentViewModelContainer() { if (!SupportParentViewModelContainers) { return; } if (HasParentViewModelContainer) { return; } _parentViewModelContainer = TargetView.FindParentViewModelContainer(); if (_parentViewModelContainer != null) { Log.Debug("Found the parent view model container '{0}' for '{1}'", _parentViewModelContainer.GetType().Name, TargetView.GetType().Name); } else { Log.Debug("Couldn't find parent view model container"); } ApiCop.UpdateRule <UnusedFeatureApiCopRule>("UserControlLogic.SupportParentViewModelContainers", rule => rule.IncreaseCount(_parentViewModelContainer != null, TargetViewType.FullName)); if (_parentViewModelContainer != null) { _parentViewModelContainer.ViewModelChanged += OnParentViewModelContainerViewModelChanged; SubscribeToParentViewModel(_parentViewModelContainer.ViewModel); } }
/// <summary> /// Initializes a new instance of the <see cref="ViewToViewModelMappingContainer" /> class. /// </summary> /// <param name="viewModelContainer">The view.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModelContainer" /> is <c>null</c>.</exception> public ViewToViewModelMappingContainer(IViewModelContainer viewModelContainer) { Argument.IsNotNull("view", viewModelContainer); var properties = viewModelContainer.GetType().GetPropertiesEx(); foreach (var property in properties) { object[] viewToViewModelAttributes = property.GetCustomAttributesEx(typeof(ViewToViewModelAttribute), false); if (viewToViewModelAttributes.Length > 0) { Log.Debug("Property '{0}' is decorated with the ViewToViewModelAttribute, creating a mapping", property.Name); var viewToViewModelAttribute = (ViewToViewModelAttribute)viewToViewModelAttributes[0]; string propertyName = property.Name; string viewModelPropertyName = (string.IsNullOrEmpty(viewToViewModelAttribute.ViewModelPropertyName)) ? propertyName : viewToViewModelAttribute.ViewModelPropertyName; var mapping = new ViewToViewModelMapping(propertyName, viewModelPropertyName, viewToViewModelAttribute.MappingType); // Store it (in 2 dictionaries for high-speed access) _viewToViewModelMappings.Add(property.Name, mapping); _viewModelToViewMappings.Add(viewModelPropertyName, mapping); } } }
/// <summary> /// Subscribes to the parent view model container. /// </summary> private void SubscribeToParentViewModelContainer() { if (!SupportParentViewModelContainers) { return; } if (HasParentViewModelContainer) { return; } _parentViewModelContainer = FindParentByPredicate(TargetControl, o => o is IViewModelContainer) as IViewModelContainer; if (_parentViewModelContainer != null) { Log.Debug("Found the parent view model container '{0}' for '{1}'", _parentViewModelContainer.GetType().Name, TargetControl.GetType().Name); } else { Log.Debug("Couldn't find parent view model container"); } if (_parentViewModelContainer != null) { _parentViewModelContainer.ViewModelChanged += OnParentViewModelContainerViewModelChanged; _parentViewModelContainer.ViewLoading += OnParentViewModelContainerLoading; _parentViewModelContainer.ViewUnloading += OnParentViewModelContainerUnloading; SubscribeToParentViewModel(_parentViewModelContainer.ViewModel); } }
/// <summary> /// Initializes a new instance of the <see cref="ViewToViewModelMappingContainer" /> class. /// </summary> /// <param name="viewModelContainer">The view.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModelContainer" /> is <c>null</c>.</exception> public ViewToViewModelMappingContainer(IViewModelContainer viewModelContainer) { Argument.IsNotNull("view", viewModelContainer); var properties = viewModelContainer.GetType().GetPropertiesEx(); foreach (var property in properties) { object[] viewToViewModelAttributes = property.GetCustomAttributesEx(typeof(ViewToViewModelAttribute), false); if (viewToViewModelAttributes.Length > 0) { Log.Debug("Property '{0}' is decorated with the ViewToViewModelAttribute, creating a mapping", property.Name); var viewToViewModelAttribute = (ViewToViewModelAttribute)viewToViewModelAttributes[0]; string propertyName = property.Name; string viewModelPropertyName = (string.IsNullOrEmpty(viewToViewModelAttribute.ViewModelPropertyName)) ? propertyName : viewToViewModelAttribute.ViewModelPropertyName; var mapping = new ViewToViewModelMapping(propertyName, viewModelPropertyName, viewToViewModelAttribute.MappingType); // Store it (in 2 dictionaries for high-speed access) _viewToViewModelMappings.Add(property.Name, mapping); _viewModelToViewMappings.Add(viewModelPropertyName, mapping); } } }
/// <summary> /// Subscribes to the parent view model container. /// </summary> private void SubscribeToParentViewModelContainer() { if (!SupportParentViewModelContainers) { return; } if (HasParentViewModelContainer) { return; } _parentViewModelContainer = TargetView.FindParentViewModelContainer(); if (_parentViewModelContainer != null) { Log.Debug("Found the parent view model container '{0}' for '{1}'", _parentViewModelContainer.GetType().Name, TargetView.GetType().Name); } else { Log.Debug("Couldn't find parent view model container"); } ApiCop.UpdateRule<UnusedFeatureApiCopRule>("UserControlLogic.SupportParentViewModelContainers", rule => rule.IncreaseCount(_parentViewModelContainer != null, TargetViewType.FullName)); if (_parentViewModelContainer != null) { _parentViewModelContainer.ViewModelChanged += OnParentViewModelContainerViewModelChanged; SubscribeToParentViewModel(_parentViewModelContainer.ViewModel); } }
/// <summary> /// Subscribes to the parent view model container. /// </summary> private void SubscribeToParentViewModelContainer() { if (!SupportParentViewModelContainers) { return; } if (HasParentViewModelContainer) { return; } _parentViewModelContainer = FindParentByPredicate(TargetControl, o => o is IViewModelContainer) as IViewModelContainer; if (_parentViewModelContainer != null) { Log.Debug("Found the parent view model container '{0}' for '{1}'", _parentViewModelContainer.GetType().Name, TargetControl.GetType().Name); } else { Log.Debug("Couldn't find parent view model container"); } if (_parentViewModelContainer != null) { _parentViewModelContainer.ViewModelChanged += OnParentViewModelContainerViewModelChanged; _parentViewModelContainer.ViewLoading += OnParentViewModelContainerLoading; _parentViewModelContainer.ViewUnloading += OnParentViewModelContainerUnloading; SubscribeToParentViewModel(_parentViewModelContainer.ViewModel); } }