C# 命名空间中不存在WPF子类

C# 命名空间中不存在WPF子类,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我目前在Visual Studio 2012中遇到问题 我有一个带有窗口的WPF项目,我想在这个窗口中放置一个个性化的类 所以我创建了一个新的C#类CarteCanvas.cs: using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Collections.Generic; using System.Linq; using System

我目前在Visual Studio 2012中遇到问题

我有一个带有窗口的WPF项目,我想在这个窗口中放置一个个性化的类

所以我创建了一个新的C#类CarteCanvas.cs:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF
{
    public class CarteCanvas : Canvas
    {
        public CarteCanvas()
        {
        }
    }
}
在MainWindow.xaml中,我这样称呼它:

<Window x:Class="WPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WPF"
        Title="Boris World" Height="600" Width="800">
    <Grid Name="mainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="400*" />
            <RowDefinition Height="170*" />
        </Grid.RowDefinitions>
        <ScrollViewer HorizontalAlignment="Stretch" Grid.Row="0">
            <local:CarteCanvas />
        </ScrollViewer>
        <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Stretch" Grid.Row="1" Stroke="Black" />
    </Grid>

</Window>

但这不起作用。我有一个错误:名称“CarteCanvas”在名称空间“clr namespace:WPF”中不存在。 当我开始写local:,自动补全显示在画布上,好像它已经被很好地识别了


我不知道我是否做得很好,或者是否有一些事情要做,但是如果你能帮助我,我将非常感激

暂时忽略该错误,然后在没有错误的情况下构建项目。然后,重新插入。(如果类型尚未内置到程序集中,XAML编辑器有时似乎无法找到或验证该类型。请不要问我为什么,我的项目中偶尔也会出现这种情况。)对我来说,XAML的可能副本似乎是正确的,可能需要重新生成。重新生成项目时,错误消息应消失。