【问题标题】:WPF PropertyGrid supports multiple selectionWPF PropertyGrid 支持多选
【发布时间】:2015-10-08 23:15:03
【问题描述】:

此文档仍然有效还是我遗漏了什么?

http://doc.xceedsoft.com/products/XceedWpfToolkit/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid~SelectedObjects.html

PropertyGrid 控件似乎没有SelectedObjectsSelectedObjectsOverride 成员。我正在使用针对 .NET Framework 4.0 的工具包的最新版本 (2.5)。

更新

@faztp12 的回答让我通过了。对于其他正在寻找解决方案的人,请按照以下步骤操作:

  1. 将您的PropertyGridSelectedObject 属性绑定到第一个选定项。像这样的:

    <xctk:PropertyGrid PropertyValueChanged="PG_PropertyValueChanged" SelectedObject="{Binding SelectedObjects[0]}"  />
    
  2. 监听PropertyGridPropertyValueChanged 事件并使用以下代码更新所有选定对象的属性值。

    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);
        }
      }
    }
    

希望这对以后的人有所帮助。

【问题讨论】:

标签: c# wpf propertygrid wpf-extended-toolkit


【解决方案1】:

当我遇到类似问题时,我订阅了PropertyValueChanged 并让List 填写了SelectedObjects

我检查了 List where 的内容是否属于同一类型,如果是,我更改了每个项目的属性:

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);
                }

我使用它是因为我需要制作一个布局设计器,这使我能够同时更改多个项目的属性:)

希望它有所帮助:)

参考Xceed Docs

【讨论】:

  • 有趣。 changeProperty 是什么?
  • PropertyValueChanged事件自带的参数:)
  • 我在PropertyValueChanged 事件中看不到任何此类参数。您确定您使用的是 Extended WPF Tookit 中的 PropertyGrid 控件吗?
  • 哎呀,对不起 :P 用changedProperty 编辑了答案 :)
  • 确实很有帮助。这终于让我通过了。谢谢一堆。我还有一件事要做。查看我的编辑。
猜你喜欢
  • 2011-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-31
  • 1970-01-01
  • 2012-09-10
相关资源
最近更新 更多