private void SelectedObjects_Changed(object sender, EventArgs e) { foreach (PropertyGridItemModel item in this) { if (item.Setter is IDisposable disposable) { disposable.Dispose(); } } this.Clear(); if (SelectedObjects?.Length > 0) { foreach (var group in SelectedObjects .SelectMany(obj => GetHashedProperties(obj as DependencyObject)) .GroupBy( p => p.HashCode, p => p)) { if (group.Count() == SelectedObjects.Length) { var prop = group.ElementAt(0).Value; PropertyInfo[] props = group .Select(item => item.Value.Element) .ToArray(); // »ý¼º ISetter setter; if (string.IsNullOrEmpty(prop.Attribute.Key)) { setter = SetterManager.CreateSetter(SelectedObjects, props); } else { setter = SetterManager.CreateSetter(SelectedObjects, props, prop.Attribute.Key); } if (setter == null) { continue; } this.AddItem( new PropertyGridItemModel(prop, setter)); } } } if (SelectedObjects?.Length == 1) { SetPresentedObject(SelectedObjects[0]); } else { SetPresentedObject(null); } }
private void SelectedObjects_Changed(object sender, EventArgs e) { foreach (PropertyGridItemModel item in this) { if (item.Setter is IDisposable disposable) { disposable.Dispose(); } } this.Clear(); if (SelectedObjects?.Length > 0 && !SelectedObjects[0].Equals(presentedObject)) { SetPresentedObject((DependencyObject)SelectedObjects[0]); foreach (var prop in DesignerManager.GetProperties(presentedObject.GetType())) { ISetter setter; if (string.IsNullOrEmpty(prop.Attribute.Key)) { setter = SetterManager.CreateSetter(presentedObject, prop.Element); } else { setter = SetterManager.CreateSetter(presentedObject, prop.Element, prop.Attribute.Key); } if (setter == null) { continue; } this.AddItem( new PropertyGridItemModel(prop, setter)); } } else { SetPresentedObject(null); } }