【发布时间】:2015-10-08 23:15:03
【问题描述】:
此文档仍然有效还是我遗漏了什么?
PropertyGrid 控件似乎没有SelectedObjects 或SelectedObjectsOverride 成员。我正在使用针对 .NET Framework 4.0 的工具包的最新版本 (2.5)。
更新
@faztp12 的回答让我通过了。对于其他正在寻找解决方案的人,请按照以下步骤操作:
-
将您的
PropertyGrid的SelectedObject属性绑定到第一个选定项。像这样的:<xctk:PropertyGrid PropertyValueChanged="PG_PropertyValueChanged" SelectedObject="{Binding SelectedObjects[0]}" /> -
监听
PropertyGrid的PropertyValueChanged事件并使用以下代码更新所有选定对象的属性值。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和SelectedObjects在Xceed.Wpf.Toolkit.PropertyGrid中不存在 -
@faztp12 似乎只有Plus版本。
标签: c# wpf propertygrid wpf-extended-toolkit