public override void SetValue(object component, object value) { string typeName = value as String; if (typeName != null && typeName.Length > 0) { ITypeProvider typeProvider = (ITypeProvider)this.ServiceProvider.GetService(typeof(ITypeProvider)); if (typeProvider == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); } Type type = typeProvider.GetType(value as string); if (type == null) { throw new Exception(SR.GetString(SR.Error_TypeNotResolved, value)); } TypeFilterProviderAttribute filterProviderAttribute = this.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute; if (filterProviderAttribute != null) { ITypeFilterProvider typeFilterProvider = null; Type typeFilterProviderType = Type.GetType(filterProviderAttribute.TypeFilterProviderTypeName); if (typeFilterProviderType != null) { typeFilterProvider = Activator.CreateInstance(typeFilterProviderType, new object[] { this.ServiceProvider }) as ITypeFilterProvider; } if (typeFilterProvider != null) { typeFilterProvider.CanFilterType(type, true); } } // we always store assembly qualified name of the type value = type.AssemblyQualifiedName; } RealPropertyDescriptor.SetValue(component, value); }
public override void SetValue(object component, object value) { object oldValue = GetValue(component); ActivityBind activityBind = value as ActivityBind; DependencyObject dependencyObj = component as DependencyObject; DependencyProperty dependencyProperty = DependencyProperty.FromName(Name, ComponentType); if (dependencyObj != null && dependencyProperty != null && activityBind != null) { ComponentChangeDispatcher componentChangeDispatcher = new ComponentChangeDispatcher(ServiceProvider, dependencyObj, this); try { if (dependencyProperty.IsEvent && ServiceProvider != null) { IEventBindingService eventBindingService = ServiceProvider.GetService(typeof(IEventBindingService)) as IEventBindingService; if (eventBindingService != null) { EventDescriptor eventDescriptor = eventBindingService.GetEvent(RealPropertyDescriptor); if (eventDescriptor != null) { RealPropertyDescriptor.SetValue(component, null); } } } dependencyObj.SetBinding(dependencyProperty, activityBind); base.OnValueChanged(dependencyObj, EventArgs.Empty); } finally { componentChangeDispatcher.Dispose(); } } else { if (dependencyObj != null && dependencyProperty != null && dependencyObj.IsBindingSet(dependencyProperty)) { ComponentChangeDispatcher componentChangeDispatcher = new ComponentChangeDispatcher(ServiceProvider, dependencyObj, this); try { dependencyObj.RemoveProperty(dependencyProperty); // Need to fire component changed event because this means we're clearing // out a previously set Bind value. If the new value matches the old value stored in the user data, // base.SetValue will do nothing but return. When that happens, if we don't fire a change // event here, we'll still have the activity bind in the code or xoml file. base.OnValueChanged(dependencyObj, EventArgs.Empty); } finally { componentChangeDispatcher.Dispose(); } } base.SetValue(component, value); } //Following code is for making sure that when we change the value from activity bind to actual value //and from actual value to activity bind; we need to change the UITypeEditor associated with property //from data binding editor to the editor specified by the user if (oldValue != value && ((oldValue is ActivityBind && !(value is ActivityBind)) || (!(oldValue is ActivityBind) && value is ActivityBind))) { TypeDescriptor.Refresh(component); } }