我正在使用Extended WPF Toolkit 3.0 Community Edition中的PropertyGrid
控件(扩展名为CollectionEditor
)。它在大多数情况下表现很好,但与使用扩展Dictionary
的自定义类相比,在您的类中声明普通Dictionary
时,行为似乎存在细微差别。
采用以下示例类:
Public Class TestObject
Public Property MyDictionary As New Dictionary(Of String, String)
End Class
以及此XAML和代码隐藏在PropertyGrid
:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:myApp"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<xctk:PropertyGrid x:Name="myPropertyGrid"/>
</Grid>
</Window>
Public Class MainWindow
Public Sub New()
InitializeComponent()
myPropertyGrid.SelectedObject = New TestObject()
End Sub
End Class
但是,如果我现在更改
的定义Public Property MyDictionary As New Dictionary(Of String, String)
到
Public Property MyDictionary As New DerivedDictionary(Of String, String)
其中DerivedDictionary
可以简单地声明为
Public Class DerivedDictionary(Of TKey, TValue)
Inherits Dictionary(Of TKey, TValue)
End Class
然后我将不再在EditableKeyValuePair`2
的组合框中显示CollectionEditor
,而是只显示KeyValuePair`2
,(您可能已经猜到)不可编辑。从代码隐藏中向DerivedDictionary
添加元素也会使它们在编辑器中显示为EditableKeyValuePair`2
,因此唯一的问题是通过UI添加新元素。
我知道我可以通过添加
来解决问题<NewItemTypes(GetType(EditableKeyValuePair(Of String, String)))>
MyDictionary
中TestObject
的声明。但是,如果我必须在一个可以通过UI编辑的类使用DerivedDictionary
的情况下执行此操作,这似乎相当冗长。
我在这里错过了一个更容易的选择吗?也许某些属性我需要应用于DerivedDictionary
才能使其有效?或者这是当前PropertyGrid
控件中的错误/限制?