2010-04-07 3 views
1

System.Windows.Documents.Paragraph에서 상속하는 클래스를 만들고 새 컬렉션 속성을 추가합니다. 여기에 그 클래스의 매우 단순화 된 표현 :Xaml 요소에서 여러 컬렉션 속성 채우기 방법

public class ExtendedParagraph : Paragraph 
{ 
    public Dictionary<string, string> Attributes { get; set; } 
} 

내가 만들고 단락의 내용과의 구성원을 할 수있는 마크 업 구문을 필요로 XAML, 내에서 위 클래스의 인스턴스를 채울 필요는 별도로 선언 할 특성 컬렉션입니다.

Paragraph 클래스는 [ContentProperty("Inlines")] 특성으로 장식되어 있으므로 인라인 및 특성 컬렉션을 명시 적으로 채워야한다고 가정합니다. 내가 다른 곳에서 비슷한 문제를 해결하는 데 사용 본 것 XAML 구문을 바탕으로,이 같은 것을 직시 :

<ExtendedParagraph xmlns="clr-namespace:MyNamespace"> 
    <ExtendedParagraph.Inlines> 

     This is where the paragraph content goes 

    </ExtendedParagraph.Inlines> 
    <ExtendedParagraph.Attributes> 

     This is where the members of the Attributes property are declared 

    </ExtendedParagraph.Attributes> 
</ExtendedParagraph> 

그러나,이 방법은 두 가지 문제를 제시한다

[1] XAML 위가 사용하는 구문 분석 할 때 XamlReader, "ExtendedParagraph.Inlines 속성이 이미 설정되어 있고 한 번만 설정할 수 있습니다"라는 메시지와 함께 실패합니다.

[2] Attributes 요소에서 KeyValuePair의 인스턴스를 선언 할 때 사용해야하는 마크 업을 모르겠습니다.

누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다.

많은 감사, 팀

편집 - 나는 질문에 대한 답을 발견했다 [1]. 더 어려운 증명 선언적 Dictionary<TKey, TValue>에 멤버를 추가하지만

<ExtendedParagraph xmlns="clr-namespace:MyNamespace"> 
    <ExtendedParagraph.Attributes> 

     This is where the members of the Attributes property are declared 

    </ExtendedParagraph.Attributes> 
    This is where the paragraph content goes 
</ExtendedParagraph> 

: 단순히 제 단락의 내용 다음 특성 컬렉션 (속성 요소 구문을 사용하여) 선언 수반한다. 나는 this post에 몇 가지 단서를 발견했지만, 아직 작업 결과를 얻지 못했습니다. 당신의 아이디어는 여전히 환영 받고 있습니다.

답변

2

나는 내 자신의 질문에 답하는 것이 괜찮은지 잘 모르겠지만 아무도 알지 못하기 때문에 내가 채택한 해결책을 나눌 것입니다.

Xaml에서 제네릭에 대한 지원이 제한되어 있습니다. 즉, Dictionary<TKey, TValue> (또는 다른 일반 컬렉션 클래스)을 채우는 기본 Xaml 관리자가 없음을 의미합니다.

<ExtendedParagraph.Attributes> 
    <generic:DictionaryOfT TypeArgument="sys:String"> 
     <generic:DictionaryOfT.Items> 
      <sys:String x:Key="String1">Hello</sys:String> 
      <sys:String x:Key="String2">World</sys:String> 
     </generic:DictionaryOfT.Items> 
    </generic:DictionaryOfT> 
</ExtendedParagraph.Attributes> 
: this article 설명으로

그러나, 선언적 컬렉션 속성을 사용자 정의 태그 확장 클래스를 작성하고, 한 번 컬렉션 멤버 유형에 맞는 구성, 성공적으로 채 웁니다 가능하다