Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: There is a way to refresh propertyGrid without reassign the selectedObject

$
0
0
Hi,

I implemented an expandable collection but when i add some objects to the collection by the propertyGrid, there is no update. So i implemented a reload function witch save the state of the propertyGrid properties, set the selectedObject to null and reassign the model. This method is not good in terms of performance and all the propertyItem are recreated. Is there a other way to do that?

Here a sample of code:
private void BackupState(PropertyItemCollection pProperties, List<Object> propertyList)
        {
            foreach (PropertyItem property in pProperties)
            {
                if (property.IsExpanded)
                {
                    List<Object> nodePropertyList = new List<Object>();
                    Dictionary<string, List<Object>> nodeDictionary = new Dictionary<string, List<Object>>();
                    if(property.Properties.Count > 0)
                        BackupState(property.Properties, nodePropertyList);
                    nodeDictionary.Add(property.PropertyDescriptor.Name, nodePropertyList);
                    propertyList.Add(nodeDictionary);
                }
            }
        }

        private void Restore(PropertyItemCollection pProperties, List<Object> propertyList)
        {
            foreach (PropertyItem property in pProperties)
            {
                if (property.IsExpandable)
                    foreach (Dictionary<string, List<Object>> dico in propertyList)
                    {
                        if (dico.ContainsKey(property.PropertyDescriptor.Name))
                        {
                            property.IsExpanded = true;
                            if(property.Properties.Count > 0)
                                Restore(property.Properties, dico[property.PropertyDescriptor.Name]);
                        }
                    }
            }
        }

private void ReloadPropertyGrid(Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid pMyPropertyGrid)
        {
            List<Object> myNodeList = new List<Object>();
            this.BackupState(pMyPropertyGrid.Properties, myNodeList);
            var tmp = propgrid.SelectedObject;
            propgrid.SelectedObject = null;
            propgrid.SelectedObject = tmp;
            this.Restore(pMyPropertyGrid.Properties, myNodeList);
        }

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>