public DataBindingDialogModel(DataPanelModel model, SceneNode targetElement, ReferenceStep targetProperty) : base(targetElement, targetProperty) { this.isBinding = true; this.addXmlDataSourceCommand = model.AddXmlDataSourceCommand; this.createSampleDataCommand = model.CreateSampleDataCommand; this.createSampleDataFromXmlCommand = model.CreateSampleDataFromXmlCommand; this.addClrObjectDataSourceCommand = model.AddClrObjectDataSourceCommand; DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(targetElement, (IPropertyId)targetProperty, true); if (dataContextInfo.DataSource.IsValidWithSource) { ISchema schemaForDataSource = SchemaManager.GetSchemaForDataSource(dataContextInfo.DataSource.SourceNode); if (schemaForDataSource != null && !(schemaForDataSource is EmptySchema)) { this.dataContext = schemaForDataSource.GetNodePathFromPath(dataContextInfo.DataSource.Path); } } this.bindsTwoWayByDefault = this.BindsTwoWayByDefault(targetElement, targetProperty); this.bindingFilterModes = new ObservableCollection <BindingFilterMode>(); this.bindingFilterModes.Add(BindingFilterMode.None); this.bindingFilterModes.Add(BindingFilterMode.FilterByType); ICollectionView defaultView = CollectionViewSource.GetDefaultView((object)this.bindingFilterModes); defaultView.MoveCurrentTo((object)BindingFilterMode.FilterByType); this.bindingSources = new ObservableCollection <IBindingSourceModel>(); this.dataSourceModel = new DataSourceBindingSourceModel(model, new DataSchemaItemFilter(this.BindingFilter)); this.AddBindingSource((IBindingSourceModel)this.dataSourceModel); if (targetElement.ViewModel.ActiveEditingContainer is SceneElement) { this.elementPropertyModel = new ElementPropertyBindingSourceModel(targetElement, new DataSchemaItemFilter(this.BindingFilter)); this.AddBindingSource((IBindingSourceModel)this.elementPropertyModel); } this.explicitDataContextModel = new ExplicitDataContextBindingSourceModel(targetElement, targetProperty, new DataSchemaItemFilter(this.BindingFilter)); this.AddBindingSource((IBindingSourceModel)this.explicitDataContextModel); this.bindingSourcesProxy = new BindingProxy <IBindingSourceModel>(); this.bindingSourcesProxy.PropertyChanged += new PropertyChangedEventHandler(this.BindingSourcesProxy_PropertyChanged); this.bindingSourcesView = (CollectionView) new DataBindingProxyCollectionView <IBindingSourceModel>(this.bindingSources, (IDataBindingProxy <IBindingSourceModel>) this.bindingSourcesProxy); BindingSceneNode binding = targetElement.GetBinding((IPropertyId)targetProperty); if (binding != null) { this.SetExistingBindingValues(binding); } else if (!(this.explicitDataContextModel.Schema is EmptySchema)) { this.bindingSourcesView.MoveCurrentTo((object)this.explicitDataContextModel); } else { this.bindingSourcesView.MoveCurrentTo((object)this.dataSourceModel); } if (binding == null || !binding.IsModeSet) { this.CurrentBindingMode = BindingPropertyHelper.GetDefaultBindingMode(this.TargetElement.DocumentNode, (IPropertyId)this.TargetProperty, this.CurrentDataPath).Mode; } this.bindingSourcesView.CurrentChanging += new CurrentChangingEventHandler(this.BindingSourcesView_CurrentChanging); defaultView.CurrentChanged += new EventHandler(this.BindingFilterModesView_CurrentChanged); this.PropertyChanged += new PropertyChangedEventHandler(this.DataBindingDialogModel_PropertyChanged); }
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 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 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); } } }