wpf Visual Studio Intellisense 仅在非常特定的情况下无法处理 XAML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17018978/
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 08:58:39  来源:igfitidea点击:

Visual Studio Intellisense not working on XAML only on very specific circumstances

wpfxamlvisual-studio-2012intellisensevisual-studio-express

提问by It'sNotALie.

I'm making a new UserControl, and when I opened it the XAML was not working.

我正在创建一个新的UserControl,当我打开它时,XAML 无法正常工作。

I thought that this was odd, as when I was working on my MainWindow it was working just fine. So I checked on my MainWindow. It still works there. Also in C# code.

我认为这很奇怪,因为当我在我的 MainWindow 上工作时它工作得很好。所以我检查了我的主窗口。它仍然在那里工作。同样在 C# 代码中。

However, if I press CTRL+       it still comes up fine.

但是,如果我按CTRL+      它仍然可以正常工作。

I'm not quite sure why. I went to Tools?Options?Text Editor?XAML?General, and the Text Completion section is greyed out (e.g. Auto-List Members, etc.). This is also greyed out when I see it on my main window, but Intellisense works there.

我不太确定为什么。我去了工具?选项?文本编辑器?XAML?一般,文本完成部分是灰色的(例如自动列表成员等)。当我在主窗口上看到它时,它也会变灰,但 Intellisense 在那里工作。



Could someone help me? My VS version is VS2012 Express, Update 2. The only extension installed is XNA (using this"hack").

有人可以帮助我吗?我的 VS 版本是 VS2012 Express, Update 2。安装的唯一扩展是 XNA(使用这个“hack”)。

采纳答案by It'sNotALie.

Huh. I just restarted it and it worked again. The problem is that before, when I restarted it, it still did not work. I haven't found the underlying issue, but it's fixed now.

呵呵。我刚刚重新启动它,它又工作了。问题是之前,当我重新启动它时,它仍然无法正常工作。我还没有找到根本问题,但现在已经解决了。

回答by usefulBee

This is one of the most frustrating things about developing wpf apps I have to say. And here is a temporary solution that was observed by chance and works every single time intellisense breaks while working with XAMl:

这是我不得不说的关于开发 wpf 应用程序最令人沮丧的事情之一。这是一个偶然观察到的临时解决方案,并且在每次使用 XAMl 时智能感知中断时都有效:

  • Break the xaml file by any means; ex: removing any char/symbol

  • Hit F6 to build

  • 以任何方式破坏xaml文件;例如:删除任何字符/符号

  • 按F6构建

Done and intellisense is back in couple seconds!

完成,智能感知在几秒钟内又回来了!

回答by The Lonely Coder

There are several reasons why Intellisense may fail and if you have several factors in play you will have to do several things to get it to work and so I've listed some of the things that I've done to solve this issue in the past.

Intellisense 可能会失败的原因有多种,如果您有多种因素在起作用,您将必须做几件事才能使其正常工作,因此我列出了我过去为解决此问题所做的一些事情.

Make sure you are using either the XAML UI Designer or the Source Code (Text)Editor for editing XAML with Intellisense. The XML (Text) editor does not provide Intellisense on my installation (VS2013 Pro).

确保使用 XAML UI 设计器或源代码(文本)编辑器通过 Intellisense 编辑 XAML。XML(文本)编辑器在我的安装(VS2013 Pro)上不提供智能感知。

If the designer crashes due to an exception in a loaded assembly you may also lose Intellisense. Fix the exception to restore it.

如果设计器由于加载的程序集中的异常而崩溃,您也可能会丢失 Intellisense。修复异常以恢复它。

The designer may not load correctly if an assembly in your project is not trusted and has been sandboxed, and this can affect Intellisense.

如果项目中的程序集不受信任且已被沙盒化,则设计器可能无法正确加载,这可能会影响 Intellisense。

See the following articles for more information on sandboxing and granting full trust:-

有关沙盒和授予完全信任的更多信息,请参阅以下文章:-

http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

http://msdn.microsoft.com/en-us/library/ee890038(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/ee890038(v=vs.110).aspx

Obviously only grant full trust to assemblies that you trust!

显然,只对您信任的程序集授予完全信任!

To grant full trust to an assembly, browse to the assembly in Windows Explorer and open the file properties and unblock the assembly (see image below).

要授予程序集完全信任,请在 Windows 资源管理器中浏览到程序集并打开文件属性并取消阻止程序集(见下图)。

enter image description here

在此处输入图片说明

Also, deleting .suo files can clear intermittent Intellisense problems.

此外,删除 .suo 文件可以清除间歇性 Intellisense 问题。

回答by Sandra

In my case, Tools / Options / Text Editor / XAML / Miscellaneous / Always open documents in full XAML view was Unchecked. After checking it and re-opening my XAML file from Solution Explorer, I had intellisence back.

就我而言,工具/选项/文本编辑器/XAML/杂项/始终以完整的 XAML 视图打开文档未选中。在检查它并从解决方案资源管理器重新打开我的 XAML 文件后,我恢复了智能。

This happened in Visual Studio 2013.

这发生在 Visual Studio 2013 中。

回答by t3chb0t

In my case setting the Properties (F4) > Build Actionof the *.XAMLto Pagefixed IntelliSense.

在我的情况下设置Properties (F4) > Build Action*.XAML,以Page固定智能感知。

回答by ΩmegaMan

In Visual Studio 2019, switching and building between Releaseand Debugmodes brought it back.

在 Visual Studio 2019 中,在ReleaseDebug模式之间切换和构建将其带回来。



x:Class out of Sync

x:类不同步

One other thing I noticed was that in the editor file of my user control, the x:Class="..."was second in line before another namespace.

我注意到的另一件事是,在我的用户控件的编辑器文件中,x:Class="..."在另一个命名空间之前排在第二位。

By putting the x:Classas the first namespace for the control, brought back intelisense.

通过将x:Class控件作为第一个命名空间,带回了智能感知。

回答by jool

I got the same issue after uninstalling Resharper from VS2019. In the options dialog the "auto list members" and related options for Text Editor->XAML was disabled.

从 VS2019 卸载 Resharper 后,我遇到了同样的问题。在选项对话框中,文本编辑器->XAML 的“自动列表成员”和相关选项被禁用。

I tried to reset the default editor for XAML to Source Code Text Editor by clicking Open With... on a XAML file, did not work.

我试图通过单击 XAML 文件上的打开方式...将 XAML 的默认编辑器重置为源代码文本编辑器,但没有奏效。

I then tried to update and even reinstall VS, nothing worked.

然后我尝试更新甚至重新安装 VS,没有任何效果。

In pure desperation I went back to the same options page as "auto list members" and disabled and then re-enabled any property ("Line Numbers" i my case). This seemed to light a spark and now it's all good again.

在纯粹的绝望中,我回到与“自动列表成员”相同的选项页面并禁用然后重新启用任何属性(我的情况是“行号”)。这似乎点燃了火花,现在一切又好了。

回答by Juansero29

?In my case, the solution to the IntelliSense on Xamarin XAML files was tied to NuGet package references, I think especially the Xamarin.Forms package. If you have the yellow warning symbol on your packages, you have to get through the following steps on your specific project: ? ?- Make sure it builds without errors

?就我而言,Xamarin XAML 文件上的 IntelliSense 解决方案与 NuGet 包引用相关联,我认为尤其是 Xamarin.Forms 包。如果你的包上有黄色警告符号,你必须在你的特定项目中完成以下步骤: ? ?- 确保它没有错误地构建

  • Pass a msbuild /restore [path to the specific project]? ?- Pass a .\nuget restoreat your solution

  • Close and reopen your solution

  • Right-click on the concerned XAML file > Open With... > Make sure to have"XAML Designer" or "Xamarin.Forms Previewer" set to default for XAML files

  • 通过一个msbuild /restore [path to the specific project]??-.\nuget restore在您的解决方案中传递一个

  • 关闭并重新打开您的解决方案

  • 右键单击相关的 XAML 文件 > 打开方式... > 确保将“XAML 设计器”或“Xamarin.Forms 预览器”设置为 XAML 文件的默认值

You should now have IntelliSense.

您现在应该拥有 IntelliSense。

? ?In my case, that made the yellow warnings disappear, then XAML IntelliSense worked again on Xamarin.Forms files

? ?就我而言,这使黄色警告消失,然后 XAML IntelliSense 再次处理 Xamarin.Forms 文件