protected void InitializeCurrentValueConverter()
        {
            if (this.TargetProperty == null)
            {
                return;
            }
            BindingSceneNode binding = this.TargetElement.GetBinding((IPropertyId)this.TargetProperty);

            if (binding == null)
            {
                return;
            }
            string str = binding.ConverterParameter as string;

            if (str != null)
            {
                this.ValueConverterParameter = str;
            }
            DocumentCompositeNode node = binding.Converter as DocumentCompositeNode;

            if (node == null)
            {
                return;
            }
            ValueConverterModel valueConverterModel = (ValueConverterModel)null;

            if (node.Type.IsResource)
            {
                string key = DocumentPrimitiveNode.GetValueAsString(ResourceNodeHelper.GetResourceKey(node));
                if (string.IsNullOrEmpty(key))
                {
                    return;
                }
                valueConverterModel = Enumerable.FirstOrDefault <ValueConverterModel>((IEnumerable <ValueConverterModel>) this.ValueConverters, (Func <ValueConverterModel, bool>)(vc => vc.DisplayName == key));
            }
            else
            {
                SceneNode sceneNode = this.ViewModel.GetSceneNode((DocumentNode)node);
                if (sceneNode != null)
                {
                    valueConverterModel = ValueConverterModelFactory.CreateValueConverterModel(sceneNode);
                    if (valueConverterModel != null)
                    {
                        this.ValueConverters.Add(valueConverterModel);
                    }
                }
            }
            if (valueConverterModel == null)
            {
                return;
            }
            this.CurrentValueConverter = valueConverterModel;
        }
 private void AddValueConverters(ResourceDictionaryNode resourceDictionary, List <ValueConverterModel> converters, List <SceneDocument> visitedDocuments)
 {
     foreach (DictionaryEntryNode dictionaryEntryNode in resourceDictionary)
     {
         ValueConverterModel valueConverter = ValueConverterModelFactory.CreateValueConverterModel((SceneNode)dictionaryEntryNode);
         if (valueConverter != null && converters.Find((Predicate <ValueConverterModel>)(vc => vc.DisplayName == valueConverter.DisplayName)) == null)
         {
             converters.Add(valueConverter);
         }
     }
     foreach (ResourceDictionaryNode resourceDictionaryNode in (IEnumerable <ResourceDictionaryNode>)resourceDictionary.MergedDictionaries)
     {
         string designTimeSource = resourceDictionaryNode.DesignTimeSource;
         if (!string.IsNullOrEmpty(designTimeSource))
         {
             IProjectDocument projectDocument = this.TargetElement.ProjectContext.OpenDocument(designTimeSource);
             if (projectDocument != null)
             {
                 this.AddDocumentConverters(projectDocument.Document as SceneDocument, converters, visitedDocuments);
             }
         }
     }
 }
Esempio n. 3
0
 private void OnAddValueConverter()
 {
     if (this.ValueConverters == null)
     {
         return;
     }
     using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(StringTable.AddValueConverterDialogTitle))
     {
         SceneNode valueConverter = AddValueConverterDialog.CreateValueConverter(this.ViewModel);
         if (valueConverter == null)
         {
             return;
         }
         ValueConverterModel valueConverterModel = ValueConverterModelFactory.CreateValueConverterModel(valueConverter);
         if (valueConverterModel == null)
         {
             return;
         }
         this.ValueConverters.Add(valueConverterModel);
         this.CurrentValueConverter = valueConverterModel;
         editTransaction.Commit();
     }
 }