Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static object GetTemplateDataContext(DocumentNode rootNode, SceneViewModel viewModel)
        {
            if (!PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)rootNode.Type))
            {
                return((object)null);
            }
            DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(viewModel.GetSceneNode(rootNode));

            if (dataContextInfo.DataSource == null || !dataContextInfo.DataSource.IsValidWithSource)
            {
                return((object)null);
            }
            object obj = (object)null;

            if (dataContextInfo.DataSource.Category == DataSourceCategory.Clr)
            {
                obj = DataContextEvaluator.CreateClrDataContext(dataContextInfo.DataSource, viewModel);
            }
            else if (dataContextInfo.DataSource.Category == DataSourceCategory.Xml)
            {
                obj = DataContextEvaluator.CreateXmlDataContext(dataContextInfo.DataSource, viewModel);
            }
            return(obj);
        }
Exemplo n.º 3
0
        private static object CreateClrDataContext(DataSourceInfo dataSource, SceneViewModel viewModel)
        {
            DocumentNode sourceNode = dataSource.SourceNode;

            if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)sourceNode.Type))
            {
                return((object)null);
            }
            object obj1 = (object)null;

            using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext))
            {
                try
                {
                    IInstanceBuilder builder  = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType);
                    ViewNode         viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode);
                    if (builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode))
                    {
                        obj1 = DataContextEvaluator.GetEvaluatedValue(viewNode.Instance);
                    }
                }
                catch
                {
                }
            }
            if (obj1 == null || string.IsNullOrEmpty(dataSource.Path))
            {
                return(obj1);
            }
            object instance = obj1;

            try
            {
                IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(dataSource.Path);
                if (list1 == null)
                {
                    return((object)null);
                }
                for (int index = 0; index < list1.Count; ++index)
                {
                    if (instance != null)
                    {
                        Type        type        = instance.GetType();
                        object      obj2        = (object)null;
                        ClrPathPart clrPathPart = list1[index];
                        if (clrPathPart.Category == ClrPathPartCategory.PropertyName)
                        {
                            PropertyInfo property = type.GetProperty(clrPathPart.Path);
                            if (property != (PropertyInfo)null)
                            {
                                obj2 = property.GetValue(instance, (object[])null);
                            }
                        }
                        else
                        {
                            CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type);
                            if (adapterDescription != null)
                            {
                                IList list2 = adapterDescription.GetCollectionAdapter(instance) as IList;
                                if (list2 != null)
                                {
                                    int result = 0;
                                    if (clrPathPart.Category == ClrPathPartCategory.IndexStep)
                                    {
                                        if (!int.TryParse(clrPathPart.Path.Trim('[', ']'), out result))
                                        {
                                            goto label_23;
                                        }
                                    }
                                    obj2 = list2[result];
                                }
                            }
                        }
label_23:
                        instance = obj2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch
            {
                instance = (object)null;
            }
            return(instance);
        }