WPF PropertyGrid支持多种选择
这个文档是否仍然有效或者我遗漏了什么?
https://doc.xceedsoft.com/products/XceedWpfToolkit/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid~SelectedObjects.html
PropertyGrid
控件似乎没有SelectedObjects
或SelectedObjectsOverride
成员。 我正在使用针对.NET Framework 4.0的Toolkit的最新版本(2.5)。
UPDATE
@ faztp12的回答让我了解了。 对于寻找解决方案的其他人,请按照下列步骤操作:
-
将
PropertyGrid
的SelectedObject
属性绑定到第一个选定的项目。 像这样的东西: -
侦听
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); } } }
希望这可以帮助有人在路上。
当我遇到类似的问题时,我做了什么,我订阅了PropertyValueChanged
并让List
填充了SelectedObjects
。
我检查了List的内容是否属于同一类型,然后如果是这样,我更改了每个项目中的属性:
PropertyItem changedProperty = (PropertyItem)e.OriginalSource; PropertyInfo t = typeof(myClass).GetProperty(changedProperty.PropertyDescriptor.Name); if (t != null) { foreach (myClass x in SelectedItems) t.SetValue(x, e.NewValue); }
我用这个是因为我需要制作一个布局设计师,这使我能够一起改变多个项目的属性:)
希望它有帮助:)
Ref Xceed Docs
上述就是C#学习教程:WPF PropertyGrid支持多种选择分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/955817.html