code

부분 선언은 서로 다른 기본 클래스를 지정할 수 없습니다.

starcafe 2023. 4. 28. 21:13
반응형

부분 선언은 서로 다른 기본 클래스를 지정할 수 없습니다.

이름이 지정된 wpf 페이지가 있습니다.StandardsDefault뒤에 있는 암호에서StandardsDefault상속 중입니다.Page다른 페이지와 마찬가지로

<Page x:Class="namespace.StandardsDefault"

public partial class StandardsDefault : Page

이제 새로운 클래스를 만들었습니다.CountryStandards계승하고 있는StandardsDefault페이지 대신에

<Page x:Class="namespace.CountryStandards"

public partial class CountryStandards : StandardsDefault

XAML을 변경하지 않았습니다. 다음과 같은 오류가 발생합니다.

"의 부분적인 선언.'CountryStandards'다른 기본 클래스를 지정해서는 안 됩니다."

디자이너가 같은 클래스를 물려받지 못하는 것이 문제일 수도 있다고 생각합니다.하지만 다음과 같은 많은 표준 페이지에서 사용되는 일반적인 방법이 많기 때문에 어떻게든 상속을 구현해야 합니다.CountryStandards

누가 저 좀 도와주실 수 있나요?

국가 표준 XAML을 다음으로 변경해야 합니다.

<src:StandardsDefault x:Class="namespace.CountryStandards" 
    xmlns:src="NamespaceOfStandardsDefault" ... />

WPF의 사용자 정의 창/페이지에서 상속하는 것에 대한 좋은 기사가 있습니다.

좀 이상한데, 아직 여기에 나열되지도 않았는데요.하지만 xaml 파일과 cs 파일이 모두 올바르게 선언되었기 때문에 위의 답변이 적용되지 않았기 때문에, 다음을 수행했고 작동하는 것처럼 보였습니다.

솔루션 폴더로 이동하거나 Visual Studio 내에서 모든 파일 표시 버튼을 클릭하고 Obj bin 폴더를 모두 삭제하면 Visual Studio가 프로젝트에 대한 모든 파일을 재생성합니다.

이제 프로젝트가 올바르게 빌드/실행되어야 합니다.

그것이 누군가에게 도움이 되기를 - 혹은 미래의 나에게.

편집: 이 수정은 일반적으로 페이지 유형을 예를 들어 ContentPage에서 CaruselPage로 변경한 후에 이 문제가 발생하는 경우에 작동합니다.

당신의CountryStandards.xaml당신은 글을 써야 합니다.

<StandardsDefault x:Class="namespace.CountryStandards"...

나의 경우: 클래스 뒤의 부분 코드는 같은 기본 클래스라도 전혀 정의해서는 안 됩니다!

오류 메시지가 혼란스럽습니다.

틀렸습니다:

xaml:
<someNamespace:SomeBaseClass x:Class="My.Namespace.ClassName" ...

C#:

namespace My.Namespace
{
    public partial class ClassName : SomeBaseClass 
    {
    }
}

오른쪽:

xaml:
<someNamespace:SomeBaseClass x:Class="My.Namespace.ClassName" ...

C#:

namespace My.Namespace
{
    public partial class ClassName
    {
    }
}

제가 비슷한 문제에 부딪혔다는 이유만으로 이 글을 올리는 것은 동일하지는 않지만, 아마도 누군가에게 도움이 될 것입니다.처음에는 사용자 컨트롤로 시작했지만 단추에서 상속하도록 컨트롤을 변경했습니다.하지만 XAML이 자동으로 업데이트되지 않아서, 제 XAML도 UserControl에서 Button으로 변경하는 것을 잊었습니다.다음과 같아야 합니다.

<Button x:Class="ThermostatGui.Shared.Controls.SetpointButton" .../>

이것이 아닌

<UserControl x:Class="ThermostatGui.Shared.Controls.SetpointButton" .../>

다른 부분 클래스가 다른 클래스를 확장하지 않는지 확인합니다.

public partial class CountryStandards : StandardsDefault

public partial class CountryStandards : Page

당신은 그들이 같은 클래스를 확장하도록 만들어야 합니다.

페이지를 루트 노드 c# 컴파일러 예상 페이지로 사용하고 있으므로 사용자 컨트롤을 생성하므로 StandardsDefault를 루트 노드로 사용해야 합니다.그러나 에서는 StandardsDefault를 기본으로 사용하고 있으므로 StandardsDefault를 루트 노드로 사용해야 합니다.

나는 완전히 속임수를 써서 사용했습니다.dynamic 것입니다. lol 의▁probably것다▁breaks입▁lol니▁in아어▁book▁every.

        Assembly a = Assembly.GetExecutingAssembly(); //get this app

        List<dynamic> l = new List<dynamic>(); //create a list

        // this list is our objects as string names
        // this if the full namespace and class, not just the class name 
        // I've actually stored these in my database so that I can control
        // ordering and show/hide from the database
        foreach(var app in listApplications) 
        {
            l.Add(a.CreateInstance(app)); //add them to my list
        }

        //as all my objects are the same this still works, you just don't get 
        //Intellisync which I don't care about because I know what I'm sending
        //all my objects are autonomous and self-contained and know nothing of any other objects
        //i have a main window/code that marshals the controls and data and manages view navigation
        l[0].DoThatFunction({ status ="new", message ="start", value = 0});

그리고 수업시간에

    public void DoThatFunction(dynamic data)
    {
        MessageBox.Show(data.message);//place-holder code but i'm sure you get the idea
    }

나는 이것이 너무 느슨하게 결합되어 있어서 좋습니다.오래된 앱을 Winforms에서 WPF로 포팅하고 있기 때문에 호환되는 코드를 문자 그대로 복사하여 붙여넣을 수 있기 때문에 적합합니다.그것은 잘못된 일일 수도 있지만, 효과가 있고 저는 많은 재작업을 줄일 수 있습니다.

또한 각 컨트롤에 100% 집중할 수 있어 테스트가 간편합니다.

언급URL : https://stackoverflow.com/questions/8800872/partial-declarations-must-not-specify-different-base-classes

반응형