Creating a WPF editor for XML file based on schema

前端 未结 4 1217
梦谈多话
梦谈多话 2021-02-01 10:08

Here\'s the scenario. We use a large XML configuration file for one of our server products. This file is fairly well layed out and is validated against an XSD file.

It\'

4条回答
  •  悲哀的现实
    2021-02-01 10:31

    To present simple xml configs (if custom editors for values are not required) one can directly bind XElement to a view using HierarchicalDataTemplate.

    xaml:

    
        
            
                
                    
                        
                        
                    
                    
            
        
    
    

    view model:

    class ConfigViewModel:INotifyPropertyChanged
    {
        public XElement Xml { get; private set;}
    
        //example of persistence infrastructure
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
        public void Load(string fileName)
        {
            Xml = XElement.Load(fileName);
            PropertyChanged(this, new PropertyChangedEventArgs("Xml"));
        }
        public void Save(string fileName)
        {
            Xml.Save(fileName);
        }
    }
    

    There are some good examples for reversed bool to visibility converter.

提交回复
热议问题