Programing

'UserControl'유형은 직접 콘텐츠를 지원하지 않습니다.

lottogame 2021. 1. 9. 09:15
반응형

'UserControl'유형은 직접 콘텐츠를 지원하지 않습니다.


Outlook 2013 및 2016 VSTO 추가 기능 프로젝트가 있고 여기에 설명 된대로 사용자 지정 작업 창에 WPF 사용자 정의 컨트롤을 추가하려고합니다 .

내가 가진 문제는 사용자 컨트롤 (WPF)을 추가 할 때 그리드가있는 WPF 컨트롤을 생성하지만 자동으로 " 'UserControl'유형은 직접 콘텐츠를 지원하지 않습니다."라는 오류가 발생한다는 것입니다.

WPF 생성 :

<UserControl x:Class="TestNamespace.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:TestNamespace"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>

</Grid>
</UserControl>

과거에는 몇 가지 작업을 수행하기 위해 WPF 프로젝트 유형 guid를 .proj 파일에 추가해야했지만이를 추가해도 아무런 차이가 없었습니다 (실제로 특정 순서로로드되지도 않음).

실물:

<ProjectTypeGuids>{BAA0C2D2-18E2-41B9-852F-F413020CAA33};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

충돌 :

<ProjectTypeGuids>{BAA0C2D2-18E2-41B9-852F-F413020CAA33};{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

충돌하지 않지만 오류를 수정하지는 않습니다.

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{BAA0C2D2-18E2-41B9-852F-F413020CAA33};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

누구든지 올바른 방향으로 나를 가리킬 수 있습니까?

최신 정보

상자에서 바로 새 클래스 라이브러리 프로젝트를 만들고 WPF 사용자 정의 컨트롤을 추가 한 다음 System.Xaml에 대한 참조를 추가했는데 동일한 문제가 있습니다.


Visual Studio 2015에서이 문제가있는 사람은 System.Xaml프로젝트에 대한 참조를 추가하십시오 (아직 추가되지 않은 경우) . Visual Studio는 단순히 참조 오류를 표시하지 않습니다.


명확한 솔루션 후에 프로젝트에 대한 참조를 추가 System.Xaml하고 UIAutomationProvider다시 빌드하십시오.


추가 System.Xaml하고 UIAutomationProvider참조한 다음 Visual Studio다시 시작 하여 문제를 해결합니다.


을 제거한 System.Xaml다음 다시 추가하십시오.


VS2017 (15.3.5)에서이 문제는 편집중인 UserControl의 기본 UserControl / Window가 동일한 라이브러리 / exe에있는 경우 발생합니다. VS를 시작한 후 몇 분 동안 괜찮은 다음 백그라운드에서 문제가 발생하고 전체 XAML 파일이 파란색 물결 모양으로 표시됩니다. 컴파일하면 사라지고 타이핑을 시작하면 즉시 돌아옵니다. Intellisense는 여전히 작동하지만 XAML 편집기를 거의 사용할 수 없게 만듭니다.

이를 고치는 유일한 방법은 기본 클래스를 다른 라이브러리로 이동하는 것입니다.


예제와 같은 새 Content 속성을 노출하고 ContentPropertyAttribute를 클래스에 사용하십시오. 나를 위해 도움이되었습니다. VS 2017에서 문제가 발생했습니다.

[ContentProperty( "Content" )]
public class MyUserControl: UserControl
{
    public new Object Content
    {
        get => base.Content;
        set => base.Content = value;
    }
    ...
}

그래서 지금은 아무것도 변경하지 않고도 완벽하게 작동하는 것처럼 보이므로 코딩 비용이 하룻밤 사이에 있었던 것 같습니다. 매우 이상하지만 적어도 지금은 계속할 수 있습니다!


Beside adding already pointed out references, I had to close and reopen solution. If even this does not solve it, restart Visual Studio.


While missing references have been mentioned as a solution, I discovered that it can also be a case of needing to resolve class ambiguities in your references.

For me, the issue was caused by an external library that had defined its own ContentPropertyAttribute in the System.Windows.Markup namespace which was causing content attributes to fail completely. Removing the reference will fix the issue, but if that is not an option, then you will have to set up a namespace alias in the reference's properties instead.

ReferenceURL : https://stackoverflow.com/questions/34070333/the-type-usercontrol-does-not-support-direct-content

반응형