WPF-名称空间中不存在CustomControl [英] WPF - CustomControl does not exist in the namespace
问题描述
在VS2015中创建新的自定义控件时遇到问题.实际上,它会生成一个包含错误
I have an issue when I create a new Custom Control in VS2015. Indeed, it generates a Themes/Generic.xaml file containing the error
名称控件MyControl在名称空间MyNamespace中不存在."
"The name CustomControl does not exist in the namespace MyNamespace".
当然,自定义控件位于名称空间MyNamespace
中,并且在xaml文件中,局部变量定义良好:
Of course, the custom control is located in the namespace MyNamespace
and in the xaml file the local variable is well defined :
xmlns:local="clr-namespace:MyNamespace"
经过一番调查,看来这是IntelliSense的一个众所周知的错误,只需重新启动即可解决该问题,但事实并非如此.
After some investigation, it appears it's a well-known bug with IntelliSense, and a simple restart should fix the problem, but it doesn't.
我尝试过
- 注释和取消注释代码
- 关闭/重新打开文件
- 重新启动Visual Studio
- 删除
%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache
中的所有文件夹
- 在调试/发布配置之间切换...
- Comment and uncomment code
- Close / Reopen the file
- Restart Visual Studio
- Delete all folders in
%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache
- Switch between Debug/Release Configurations...
错误仍然存在.
我没有碰过IDE为CustomControl生成的任何行代码,所以也许我错过了一些东西吗?
I didn't touch any line code generated by the IDE for the CustomControl, so maybe I missed something ?
using System.Windows;
using System.Windows.Controls;
namespace MyNamespace
{
public class CustomControl : Control
{
static CustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl)));
}
}
}
谢谢.
推荐答案
我终于找到了解决方法,这似乎是与CPU目标有关的问题.我正在为x64进行构建,但是如果我选择任何CPU"和首选32位",则Designer可以在名称空间中找到所有成员.也许是因为Visual Studio是32位应用程序而发生的?再次谢谢你.
I finally found a workaround, it seems to be a problem related to CPU target. i was building for x64 but if I choose "Any CPU" and "Prefer 32bits", the Designer is able to find all members in namespaces. Maybe this occurs because Visual Studio is a 32bits application ? Thank you again.
这篇关于WPF-名称空间中不存在CustomControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!