2010-02-15 2 views
10

내 작은 응용 프로그램에 MVC 디자인을 시도하고 싶습니다.어떻게 UserControl을 확장하는 클래스를 사용자 정의 컨트롤로 확장 할 수 있습니까?

UserControl을 확장하는 일반 Csharp 클래스 ViewBase가 있습니다. 단일 .cs 파일입니다.

ViewBase를 확장하려는 여러 클래스가 있습니다. 이들은 실제 UserControls이므로 .cs 파일과 .xaml 파일 뒤에 코드가 있습니다.

그러나 CSharp는 이러한 클래스에 대해 기본 클래스가 "다른 부분에 선언 된 것과 다릅니다"라고 알려줍니다.

내가하고 싶은 일이 전혀 가능하지 않습니까? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

XAML 파일을 수정하지 않았으므로 여전히 태그를 사용합니다.

다음은 관련 코드입니다 :

// This gives the error in question and ViewBase is underlined 
// "Base class of LoginView differs from declared in other parts" 
public partial class LoginView : ViewBase { 
    public LoginView(Shell shell, ControllerBase controller) : base(shell, controller) { 
     InitializeComponent(); 
    } 
} 

// This one is a single .cs file 
public abstract class ViewBase : UserControl { 
    public Shell Shell { get; set; } 
    public ControllerBase Controller { get; set; } 

    protected ViewBase(Shell shell, ControllerBase controller) 
    { 
     Shell = shell; 
     Controller = controller; 
    } 
} 

답변

21

주 내 XAML 파일을 수정하지 않았다, 그래서 그들은 아직 태그 문제를의

를 사용합니다.

<UserControl ...> 
    ... 
</UserControl> 

문제는 한 곳합니다 (.cs 파일) 및 UserControl에서 당신이 ViewBase 상속하고있는 컴파일러를 말하는 것입니다

<local:ViewBase xmlns:local="clr-namespace:..." 
    ... 
</local:ViewBase> 

에 : 당신은 변경해야합니다 다른 파일 ( .xaml 파일).

+0

대단히 감사합니다! –

+0

약간의 정교함이 필요합니다. –

관련 문제