KeyValuePair<int,MyClass>
을 WPF의 DataTemplate에 대한 데이터 형식으로 지정하려고합니다. KeyValuePair는 관련이 경우 내가 Dr WPF's implementation을 사용하고 ObservableDictionary
객체 (에서입니다.KeyValuePair에 대한 DataTemplate 정의
내가 컴파일러 오류를 얻고있다, 그러나, 나는 가까운 무언가를 얻을 수 있었다 How to reference a generic type in the DataType attribute of a HierarchicalDataTemplate? 사용.
내가 할 수 있어야합니다 . KeyValuePair 그래서 나는 사전의 가치 개체의 일부 컬렉션을 포함 아래에있는 트 리뷰에서 또 다른 잎을 만들 수 있습니다에 대한 HierarchicalDataTemplate을 정의 할 수
XAML은 단순히 :
<HierarchicalDataTemplate DataType="{local:GenericKeyValuePairType
KeyType=sys:Int32,
ValueType=local:MyClass}"
ItemsSource="{Binding Path=Value.MyList}" />
,
그리고 GenericKeyValuePairType 내가이 작업을 수행 할 때, 비주얼 스튜디오는이 유효하지 않음을 나타내는 MarkupExtension
public class GenericKeyValuePairType : MarkupExtension
{
public Type KeyType { get; set; }
public Type ValueType { get; set; }
public GenericKeyValuePairType() { }
public GenericKeyValuePairType(Type keyType, Type valueType)
{
KeyType = keyType;
ValueType = valueType;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return typeof(KeyValuePair<,>).MakeGenericType(this.KeyType, this.ValueType);
}
}
입니다. 특정 오류 :
사전의 키 유형은 'TreeViewBindingTest.GenericKeyValuePairType'일 수 없습니다. String, TypeExtension 및 StaticExtension 만 지원됩니다.
내가 할 수있는 일이 가능한 것입니까? 그렇다면 더 나은 접근 방법이 있습니까?
거기에 연결된 스레드에서 사전에 대한 xaml의 예가 있습니다. 그 구현을 사용할 수없는 이유는 무엇입니까? 나는 당신이하려고하는 것을 오해하고있을 수도 있습니다. – Default
@Default Value 객체가 TreeView의 또 다른 리프가 될 다른 컬렉션을 가지고 있으므로 사전을 사용하여 KeyValuePair에 대해 'HierarchicalDataTemplate'을 정의해야합니다. 그래서 그 아래에 구조를 정의 할 수 있어야합니다. 'Values' 속성에 연결하려고했는데'Values' 콜렉션을 볼 수 없기 때문에'TreeView'에 사전에 대한 변경 사항이 표시되지 않습니다 – psubsee2003
'HierarchicalDataTemplate'에서 당신은'MyList '를 'ItemsSource'로 변경하십시오. 그러나'KeyValuePair'는'MyList' 속성을 가지고 있지 않습니다. MyClass가 템플릿의 소스가 될 수 있습니까? –