Windows Presentation Foundation (WPF) 项目不支持控件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31005664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:13:28  来源:igfitidea点击:

Controls is not Supported in the Windows Presentation Foundation (WPF) Project

c#wpfuser-controlsxml-namespaces

提问by Bronze Harold Brown

I am trying to use a user controland I have tried a few different solutions but, I have not been able to fix this issue:

我正在尝试使用 auser control并且尝试了几种不同的解决方案,但是,我无法解决此问题:

In my main window, I have written code like below:

在我的主窗口中,我编写了如下代码:

   <Window x:Class="WPF_Work_Timer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPF_Work_Timer"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TabControl>
            ...
            <TabItem Header="This Week">
                <controls.WeekView></controls.WeekView> 
                <!-- ^Controls is not supported in WPF Error is here. -->
            </TabItem>
            ...
        </TabControl>
    </Grid>
</Window>

I have written code like below for the User Control:

我已经为以下代码编写了如下代码User Control

 <UserControl x:Class="WPF_Work_Timer.WeekView"
             x:Name="WeekViewControl"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        ...
    </Grid>
</UserControl>

I have searched for a solution for this issue and I am sure that I am missing something very simple.

我已经为这个问题寻找了解决方案,而且我确信我遗漏了一些非常简单的东西。

回答by rory.ap

The problem is you're using a period .instead of a colon :. Try this:

问题是您使用的是句号.而不是冒号:。尝试这个:

<controls:WeekView></controls:WeekView>