programing

XAML: 속성 'Resources'가 두 번 이상 설정되었습니다.

css3 2023. 4. 15. 09:11

XAML: 속성 'Resources'가 두 번 이상 설정되었습니다.

다음의 에러가 표시됩니다.

'Resources' 속성이 두 번 이상 설정되었습니다.

XAML은 다음과 같습니다.

<UserControl.Resources>
    <!--Resource dictionaries for framework stuff-->
    <ResourceDictionary>
        <Style x:Key="MultiLineTextBox" TargetType="TextBox">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
        </Style>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/View;component/Common/ResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    <!--Convertors needed for proper display-->
    <c:CollapsedIfNegative x:Key="CollapseIfNegative"/>
    <c:VisibleIfNegative x:Key="MakeVisibleIfNegative"/>
    <c:ErrorCodeToString x:Key="ConvertErrorCodeToString"/>
</UserControl.Resources>

.ResourcesXaml의 속성은 영리하다: 타입ResourceDictionary하지만, 만약 당신이 명시적으로<ResourceDictionary>그 내용을 태그하면 컴파일러가 마법처럼 추정합니다.그래서 보통 붓을 바로 마크업에 넣을 수 있어요.

하지만, 당신은 당신 자신의 것을 넣는 것으로 시작했습니다.ResourceDictionary그래서 컴파일러는 당신이 두 개 이상의 값을 설정하려고 한다고 생각합니다.이렇게 다시 쓰면 원하는 결과를 얻을 수 있습니다.

<UserControl.Resources>
    <!--Resource dictionaries for framework stuff-->
    <ResourceDictionary>
        <!--Convertors needed for proper display-->
        <!-- move this INSIDE the ResourceDictionary tag -->
        <c:CollapsedIfNegative x:Key="CollapseIfNegative"/>
        <c:VisibleIfNegative x:Key="MakeVisibleIfNegative"/>
        <c:ErrorCodeToString x:Key="ConvertErrorCodeToString"/>


        <Style x:Key="MultiLineTextBox" TargetType="TextBox">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
        </Style>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/View;component/Common/ResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

실제로 XAML을 복사하여 사용자 제어에 붙여넣으면 문제없이 구축됩니다(참조된 변환기 클래스를 추가할 경우).

에러 리스트에 다른 에러가 표시됩니까?아니면 이 에러만 표시됩니까?리소스를 찾지 못하는 등 다른 오류가 발생하면 다른 컴파일 오류가 발생할 수 있습니다.

언급URL : https://stackoverflow.com/questions/3425720/xaml-the-property-resources-is-set-more-than-once