0

我試圖在Xceed PropertyGrid中顯示XmlElement的屬性。爲此,我定義了自定義包裝類。它包裝XmlElement,遍歷XmlAttributes併爲每個XmlAttribute創建自定義PropertyDescriptor。所有「虛擬」屬性的類型是String。一切正常。 現在我想要爲每個具有有限值的屬性設置可能屬性值的下拉列表。在Xceed的PropertyGrid中,有ItemsSourceAttribute。但它有如下被應用:WPFExtendedToolkit PropertyGrid標準值

ItemsSourceAttribute(typeof(MyCustomItemsSource)) 

而且這裏的問題是 - 我不能爲MyCustomItemsSource構造提供正確的參數。我能做些什麼呢?

似乎還有另一種可能性 - 定義TypeConverter,覆蓋GetStandardValues,並將此轉換器提供給「虛擬」屬性。但PropertyGrid只是忽略了這個屬性。

Xceed PropertyGrid可以完成這個簡單的任務嗎?

回答

0

已解決。我實現了自定義編輯器

public class AttributeValuesEditor: Xceed.Wpf.Toolkit.PropertyGrid.Editors.ComboBoxEditor 
{ 
    protected override IEnumerable CreateItemsSource(PropertyItem propertyItem) 
    { 
     var property = propertyItem.PropertyDescriptor as XmlAttributePropertyDescriptor; 
     Debug.Assert(property!=null); 
     return property.GetCompletionValues(); 
    } 
} 

這裏,上下文以PropertyItem的形式傳遞給方法。現在可以區分不同的屬性並返回適當的項目。