2011-09-18 3 views
2

사용자 컨트롤 MyUserControl을 만들었습니다. 이제 MyUserControl에서 파생 된 MyCustomControl 사용자 지정 컨트롤을 만들고 싶습니다. MyCustomControl.cs 코드는 다음입니다 :ArgumentException 사용자 컨트롤에서 파생 된 사용자 지정 컨트롤의 DefaultStyleKey - Silverlight 4

내가 테마를 가지고
public class MyCustomControl : MyUserControl 
    { 
     public MyCustomControl() 
     { 
      this.DefaultStyleKey = typeof(MyCustomControl); 
     } 
    } 

/generic.xaml을 내가 줄을 실행 ArgumentException이를 얻을 수 런타임에 MyCustomControl 인스턴스화 스타일

<Style TargetType="local:MyCustomControl"> 
... 
</Style> 

와 파일

this.DefaultStyleKey = typeof(MyCustomControl); 

무엇이 누락 되었습니까?

답변

2

UserControl에서 DefaultStyleKey으로 파생 된 유형을 지정하면 ArgumentException을 던져서 명시 적으로 허용되지 않습니다 (왜 ArgumentException 및 왜 SL 팀에서만 알고있는 설명 메시지가 없는지).

UserControl은 자체의 연결된 Xaml 대신 템플릿으로 수신 할 수 없습니다. 그 점은 UserControl입니다. MyUserControl을 templatable 컨트롤로 변환해야합니다. 시도하는 방식대로 상속 받고 싶다면 잘되었습니다.

+0

나는 본다. 감사! CustomControl1을 기본 스타일로 생성 한 다음 CustomControl2에서 생성 한 CustomControl2를 CustomControl2와 함께 만들 수 있습니까? 처음에이 시나리오를 시도했지만 런타임에 System.Exception이 발생했습니다. – EvAlex

관련 문제