protected override IPropertyId GetDefaultPropertySelection() { Type type = this.BindingPath.Node.Type; IType dataType = (IType)null; SceneViewModel viewModel = this.TargetElement.ViewModel; if (type != (Type)null) { dataType = viewModel.ProjectContext.GetType(type); } if (dataType == null) { dataType = viewModel.ProjectContext.ResolveType(PlatformTypes.Object); } IProperty property = BindingPropertyHelper.GetDefaultBindingPropertyInfo(this.TargetElement, dataType).Property; if (this.targetBindableProperties.IndexOf((ReferenceStep)property) < 0) { property = (IProperty)null; } if (property == null && dataType != null) { foreach (ReferenceStep referenceStep in (IEnumerable <ReferenceStep>) this.targetBindableProperties) { if (BindingPropertyHelper.GetPropertyCompatibility((IProperty)referenceStep, dataType, (ITypeResolver)this.ViewModel.ProjectContext) != BindingPropertyCompatibility.None) { property = (IProperty)referenceStep; break; } } } return((IPropertyId)property); }
protected void SetCommonBindingValues(BindingSceneNode binding) { IDocumentContext documentContext = binding.DocumentContext; bool flag = !string.IsNullOrEmpty(binding.Path) || binding.SupportsXPath && !string.IsNullOrEmpty(binding.XPath); BindingMode bindingMode = this.CurrentBindingMode; if (!flag && (bindingMode == BindingMode.Default || bindingMode == BindingMode.OneWayToSource || bindingMode == BindingMode.TwoWay)) { bindingMode = BindingMode.OneWay; } if (bindingMode == BindingMode.TwoWay && binding.SupportsUpdateSourceTrigger) { if (binding.GetDefaultValue(BindingSceneNode.UpdateSourceTriggerProperty) == this.CurrentUpdateSourceTrigger) { binding.ClearLocalValue(BindingSceneNode.UpdateSourceTriggerProperty); } else { binding.UpdateSourceTrigger = this.CurrentUpdateSourceTrigger; } } BindingModeInfo defaultBindingMode = BindingPropertyHelper.GetDefaultBindingMode(this.TargetElement.DocumentNode, (IPropertyId)this.TargetProperty, this.CurrentDataPath); if (defaultBindingMode.IsOptional && defaultBindingMode.Mode == bindingMode) { binding.ClearLocalValue(BindingSceneNode.ModeProperty); } else { binding.Mode = bindingMode; } if (!string.IsNullOrEmpty(this.BindingFallbackValue)) { binding.FallbackValue = (DocumentNode)documentContext.CreateNode(this.BindingFallbackValue); } SceneNode sceneNode = (SceneNode)null; if (this.CurrentValueConverter != null) { sceneNode = this.CurrentValueConverter.GenerateConverter(); } else if (this.originalValueConverter != null) { sceneNode = this.ViewModel.GetSceneNode(this.originalValueConverter.Clone(binding.DocumentContext)); } if (sceneNode != null) { binding.SetValueAsSceneNode(BindingSceneNode.ConverterProperty, sceneNode); } if (string.IsNullOrEmpty(this.valueConverterParameter)) { return; } binding.ConverterParameter = (object)this.valueConverterParameter; }
public static IList <ReferenceStep> GetBindableProperties(SceneNode sceneNode, IType targetPropertyType) { IList <ReferenceStep> sourceProperties = BindingPropertyHelper.GetBindableSourceProperties(sceneNode); for (int index = sourceProperties.Count - 1; index >= 0; --index) { if (!MiniSourceBindingDialogModel.IsValidProperty(sceneNode, sourceProperties[index], targetPropertyType)) { sourceProperties.RemoveAt(index); } } return(sourceProperties); }
public MiniTargetBindingDialogModel(DataSchemaNodePath bindingPath, SceneNode targetElement, ReferenceStep targetProperty, bool useDesignDataContext) : base(bindingPath, targetElement, targetProperty) { this.useDesignDataContext = useDesignDataContext; this.targetBindableProperties = BindingPropertyHelper.GetBindableTargetProperties(this.TargetElement); IProperty dataContextProperty = DataContextHelper.GetDataContextProperty(this.TargetElement.Type); if (dataContextProperty != null && !this.TargetElement.ViewModel.BindingEditor.CanCreateAndSetBindingOrData(targetElement, (IPropertyId)dataContextProperty, bindingPath, true)) { this.targetBindableProperties.Remove((ReferenceStep)dataContextProperty); } this.Initialize(); }
public BindingDialogModelBase(SceneNode targetElement, ReferenceStep targetProperty) { this.TargetElement = targetElement; this.TargetProperty = targetProperty; IType type1 = this.ViewModel.ProjectContext.ResolveType(PlatformTypes.BindingMode); this.supportedBindingModeNames = Enum.GetNames(type1.RuntimeType); this.bindingModeProxy = new BindingProxy <BindingMode>(); this.bindingModesCollection = new ObservableCollection <BindingMode>(); foreach (BindingMode bindingMode in this.bindingModes) { if (this.IsBindingModeSupported(bindingMode)) { this.bindingModesCollection.Add(bindingMode); } } this.bindingModesView = (CollectionView) new DataBindingProxyCollectionView <BindingMode>(this.bindingModesCollection, (IDataBindingProxy <BindingMode>) this.bindingModeProxy); this.bindingModesView.MoveCurrentToFirst(); this.bindingModeProxy.Value = BindingPropertyHelper.GetDefaultBindingMode(this.TargetElement.DocumentNode, (IPropertyId)this.TargetProperty, (DataSchemaNodePath)null).Mode; if (this.TargetProperty != null) { BindingSceneNode binding = this.TargetElement.GetBinding((IPropertyId)this.TargetProperty); if (binding != null) { this.originalValueConverter = binding.Converter; } } this.updateSourceTriggerProxy = new BindingProxy <object>(); ObservableCollection <object> collection = new ObservableCollection <object>(); IType type2 = this.ViewModel.ProjectContext.ResolveType(PlatformTypes.UpdateSourceTrigger); if (!this.ViewModel.ProjectContext.PlatformMetadata.IsNullType((ITypeId)type2)) { IProperty property = this.ViewModel.ProjectContext.ResolveProperty(BindingSceneNode.UpdateSourceTriggerProperty); if (property != null) { this.updateSourceTriggerProxy.Value = property.GetDefaultValue(type1.RuntimeType); } foreach (object obj in (IEnumerable)MetadataStore.GetTypeConverter(type2.RuntimeType).GetStandardValues()) { collection.Add(obj); } } this.updateSourceTriggersView = (CollectionView) new DataBindingProxyCollectionView <object>(collection, (IDataBindingProxy <object>) this.updateSourceTriggerProxy); }
private static bool IsPropertyBindable(SceneNode sceneNode, PropertyReference propertyReference, BindingPropertyHelper.BindingType type) { if (!BindingPropertyHelper.IsBindableSceneNode(sceneNode)) { return(false); } ReferenceStep lastStep = propertyReference.LastStep; if (BindingPropertyHelper.IsTargetMode(type)) { bool isDeclaringTypeBindable = propertyReference.Count <= 1 ? BindingPropertyHelper.IsBindableType(sceneNode.Type.NearestResolvedType, BindingPropertyHelper.BindingType.Target) : BindingPropertyHelper.IsBindableType(lastStep.DeclaringType, BindingPropertyHelper.BindingType.Target); if (!BindingPropertyHelper.IsPropertyBindableAsTarget(sceneNode, lastStep, isDeclaringTypeBindable)) { return(false); } } return(!BindingPropertyHelper.IsSourceMode(type) || BindingPropertyHelper.IsPropertyBindableAsSource(sceneNode, lastStep)); }
public static BindingPropertyMatchInfo GetDefaultBindingPropertyInfo(SceneNode sceneNode, IType dataType) { BindingPropertyMatchInfo bestProperty = new BindingPropertyMatchInfo((IProperty)null); IProperty property = sceneNode.ProjectContext.ResolveProperty(BaseFrameworkElement.DataContextProperty); for (IType type = sceneNode.Type; type != null; type = type.BaseType) { ReferenceStep propertyInternal = BindingPropertyHelper.GetDefaultBindingPropertyInternal(type.NearestResolvedType, sceneNode.ProjectContext); if (propertyInternal != null && BindingPropertyHelper.IsPropertyBindable(sceneNode, new PropertyReference(propertyInternal), BindingPropertyHelper.BindingType.Target)) { BindingPropertyMatchInfo propertyMatchInfo = new BindingPropertyMatchInfo((IProperty)propertyInternal); propertyMatchInfo.Compatibility = propertyInternal != property?BindingPropertyHelper.GetPropertyCompatibility(propertyMatchInfo, dataType, (ITypeResolver)sceneNode.ProjectContext) : BindingPropertyCompatibility.DataContext; bestProperty = BindingPropertyHelper.GetBetterProperty(bestProperty, propertyMatchInfo); } } return(bestProperty); }
private static bool IsValidProperty(SceneNode sceneNode, ReferenceStep referenceStep, IType targetPropertyType) { if (referenceStep.IsAttachable) { return(false); } IType type1 = targetPropertyType.NullableType ?? targetPropertyType; if (PlatformTypes.String.Equals((object)type1) || PlatformTypes.Object.Equals((object)type1)) { return(true); } IType type2 = referenceStep.PropertyType.NullableType ?? referenceStep.PropertyType; if (type1.IsAssignableFrom((ITypeId)type2)) { return(BindingPropertyHelper.IsPropertyValidBindingSource(sceneNode, referenceStep)); } return(false); }
protected override IPropertyId GetDefaultPropertySelection() { BindingPropertyMatchInfo bindingPropertyInfo = BindingPropertyHelper.GetDefaultBindingPropertyInfo(this.TargetElement, this.targetPropertyType); if (bindingPropertyInfo.Compatibility != BindingPropertyCompatibility.None) { ReferenceStep referenceStep = (ReferenceStep)bindingPropertyInfo.Property; if (this.sourceBindingProperties.Contains(referenceStep)) { return((IPropertyId)referenceStep); } } foreach (ReferenceStep referenceStep in (IEnumerable <ReferenceStep>) this.sourceBindingProperties) { if (this.targetPropertyType != null && this.targetPropertyType.IsAssignableFrom((ITypeId)referenceStep.PropertyType)) { return((IPropertyId)referenceStep); } } return((IPropertyId)null); }
public static IList <ReferenceStep> GetBindableTargetProperties(SceneNode sceneNode) { return(BindingPropertyHelper.GetBindablePropertiesInternal(sceneNode, int.MaxValue, BindingPropertyHelper.BindingType.Target)); }
public static bool IsPropertyBindable(SceneNode sceneNode, ReferenceStep referenceStep) { return(BindingPropertyHelper.IsPropertyBindable(sceneNode, new PropertyReference(referenceStep))); }
public static bool IsPropertyBindable(SceneNode sceneNode, PropertyReference propertyReference) { return(BindingPropertyHelper.IsPropertyBindable(sceneNode, propertyReference, BindingPropertyHelper.BindingType.Target)); }
public static bool AnyBindableProperties(SceneNode sceneNode, IType targetPropertyType) { return(Enumerable.Any <ReferenceStep>((IEnumerable <ReferenceStep>)BindingPropertyHelper.GetBindableSourceProperties(sceneNode), (Func <ReferenceStep, bool>)(prop => MiniSourceBindingDialogModel.IsValidProperty(sceneNode, prop, targetPropertyType)))); }
private void UpdateBindingModes() { if (!this.IsBinding) { return; } if (!this.IsExpanded) { this.CurrentBindingMode = BindingPropertyHelper.GetDefaultBindingMode(this.TargetElement.DocumentNode, (IPropertyId)this.TargetProperty, this.CurrentDataPath).Mode; } else { DataSchemaNodePath relativeSchemaPath = this.CurrentRelativeSchemaPath; bool flag = false; if (relativeSchemaPath != null) { if (!relativeSchemaPath.Node.IsReadOnly && relativeSchemaPath.Node != relativeSchemaPath.Schema.Root) { flag = true; } } else if (this.UseCustomBindingExpression && !string.IsNullOrEmpty(this.CustomBindingExpression)) { flag = true; } if (this.canSetTwoWayBinding.HasValue && this.canSetTwoWayBinding.Value == flag) { return; } this.canSetTwoWayBinding = new bool?(flag); if (flag) { if (!this.BindingModesCollection.Contains(BindingMode.TwoWay) && this.IsBindingModeSupported(BindingMode.TwoWay)) { this.BindingModesCollection.Add(BindingMode.TwoWay); } if (!this.BindingModesCollection.Contains(BindingMode.OneWayToSource) && this.IsBindingModeSupported(BindingMode.OneWayToSource)) { this.BindingModesCollection.Add(BindingMode.OneWayToSource); } if (this.BindingModesCollection.Contains(BindingMode.Default) || !this.IsBindingModeSupported(BindingMode.Default)) { return; } this.BindingModesCollection.Insert(0, BindingMode.Default); } else { if (this.CurrentBindingMode == BindingMode.TwoWay || this.CurrentBindingMode == BindingMode.OneWayToSource || this.bindsTwoWayByDefault && this.CurrentBindingMode == BindingMode.Default) { if ((relativeSchemaPath != null ? relativeSchemaPath.Node : (DataSchemaNode)null) == null) { if (this.bindsTwoWayByDefault) { this.CurrentBindingMode = BindingMode.OneWay; } else { this.CurrentBindingMode = (BindingMode)this.TargetElement.ProjectContext.GetCapabilityValue(PlatformCapability.DefaultBindingMode); } } else { this.CurrentBindingMode = BindingPropertyHelper.GetDefaultBindingMode(this.TargetElement.DocumentNode, (IPropertyId)this.TargetProperty, relativeSchemaPath).Mode; } } this.BindingModesCollection.Remove(BindingMode.TwoWay); this.BindingModesCollection.Remove(BindingMode.OneWayToSource); if (!this.bindsTwoWayByDefault) { return; } this.BindingModesCollection.Remove(BindingMode.Default); } } }
public static bool IsPropertyValidBindingSource(SceneNode sceneNode, ReferenceStep referenceStep) { return(BindingPropertyHelper.IsPropertyBindable(sceneNode, new PropertyReference(referenceStep), BindingPropertyHelper.BindingType.Source)); }
private static IList <ReferenceStep> GetBindablePropertiesInternal(SceneNode sceneNode, int maxCount, BindingPropertyHelper.BindingType bindingType) { List <ReferenceStep> list = new List <ReferenceStep>(); if (!BindingPropertyHelper.IsBindableSceneNode(sceneNode)) { return((IList <ReferenceStep>)list); } bool isDeclaringTypeBindable = BindingPropertyHelper.IsBindableType(sceneNode.Type.NearestResolvedType, bindingType); foreach (TargetedReferenceStep targetedReferenceStep in (IEnumerable <TargetedReferenceStep>)PropertyMerger.GetMergedProperties((IEnumerable <SceneNode>) new SceneNode[1] { sceneNode })) { if ((!BindingPropertyHelper.IsTargetMode(bindingType) || BindingPropertyHelper.IsPropertyBindableAsTarget(sceneNode, targetedReferenceStep.ReferenceStep, isDeclaringTypeBindable)) && (!BindingPropertyHelper.IsSourceMode(bindingType) || BindingPropertyHelper.IsPropertyBindableAsSource(sceneNode, targetedReferenceStep.ReferenceStep))) { list.Add(targetedReferenceStep.ReferenceStep); if (list.Count >= maxCount) { break; } } } return((IList <ReferenceStep>)list); }
public static bool HasBindableProperties(SceneNode sceneNode) { return(BindingPropertyHelper.GetBindablePropertiesInternal(sceneNode, 1, BindingPropertyHelper.BindingType.Target).Count > 0); }
internal static bool IsBindableType(IType type) { return(BindingPropertyHelper.IsBindableType(type, BindingPropertyHelper.BindingType.Target)); }
private static bool IsBindableType(IType type, BindingPropertyHelper.BindingType bindingType) { return(!(type.RuntimeType == (Type)null) && (!BindingPropertyHelper.IsTargetMode(bindingType) || (!type.PlatformMetadata.IsCapabilitySet(PlatformCapability.SupportsDependencyObjectDatabinding) ? PlatformTypes.FrameworkElement : PlatformTypes.DependencyObject).IsAssignableFrom((ITypeId)type))); }
public static BindingPropertyCompatibility GetPropertyCompatibility(IProperty property, IType dataType, ITypeResolver typeResolver) { return(BindingPropertyHelper.GetPropertyCompatibility(new BindingPropertyMatchInfo(property), dataType, typeResolver)); }