这份文档是否仍然有效,或者我有所遗漏?
PropertyGrid
控件似乎没有SelectedObjects
或SelectedObjectsOverride
成员。我正在使用针对.NET Framework 4.0的最新版本(2.5)的工具包。
更新
@faztp12的答案帮助了我。对于其他正在寻找解决方案的人,请按照以下步骤操作:
Bind your
PropertyGrid
'sSelectedObject
property to the first selected item. Something like this:<xctk:PropertyGrid PropertyValueChanged="PG_PropertyValueChanged" SelectedObject="{Binding SelectedObjects[0]}" />
Listen to
PropertyValueChanged
event of thePropertyGrid
and use the following code to update property value to all selected objects.private void PG_PropertyValueChanged(object sender, PropertyGrid.PropertyValueChangedEventArgs e) { var changedProperty = (PropertyItem)e.OriginalSource; foreach (var x in SelectedObjects) { //make sure that x supports this property var ProperProperty = x.GetType().GetProperty(changedProperty.PropertyDescriptor.Name); if (ProperProperty != null) { //fetch property descriptor from the actual declaring type, otherwise setter //will throw exception (happens when u have parent/child classes) var DeclaredProperty = ProperProperty.DeclaringType.GetProperty(changedProperty.PropertyDescriptor.Name); DeclaredProperty.SetValue(x, e.NewValue); } } }
2.5
,但在Xceed.Wpf.Toolkit.PropertyGrid
中找不到SelectedObjects
。 - fahimalizain