public static SceneNode CreateValueConverter(SceneViewModel viewModel)
        {
            AddValueConverterDialog valueConverterDialog = new AddValueConverterDialog(viewModel);
            bool?nullable = valueConverterDialog.ShowDialog();

            if ((!nullable.GetValueOrDefault() ? 0 : (nullable.HasValue ? true : false)) != 0)
            {
                Type   objectType = valueConverterDialog.ObjectType;
                string name       = valueConverterDialog.ValueConverterResourceKey;
                if (objectType != (Type)null)
                {
                    viewModel.ProjectContext.GetType(objectType);
                    SceneNode sceneNode = viewModel.CreateSceneNode(objectType);
                    SceneNode rootNode  = viewModel.RootNode;
                    if (rootNode != null)
                    {
                        Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureResourceDictionaryNode(rootNode);
                        ResourceDictionaryNode resourceDictionaryNode = ResourceManager.ProvideResourcesForElement(rootNode);
                        if (resourceDictionaryNode != null)
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                name = objectType.Name;
                            }
                            string uniqueResourceKey = resourceDictionaryNode.GetUniqueResourceKey(name);
                            DictionaryEntryNode dictionaryEntryNode = DictionaryEntryNode.Factory.Instantiate((object)uniqueResourceKey, sceneNode);
                            resourceDictionaryNode.Insert(0, dictionaryEntryNode);
                            return((SceneNode)dictionaryEntryNode);
                        }
                    }
                }
            }
            return((SceneNode)null);
        }
Exemple #2
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();
     }
 }