简体   繁体   English

如何忽略VS2010中的显式错误?

[英]How to ignore an explicit error in VS2010?

I would like VS2010 to ignore an error in XAML Code. 我希望VS2010忽略XAML代码中的错误。 The Reason is, it's not a real error, I have a own class of Windows and VS is not able to create an instance of it. 原因是,这不是真正的错误,我有自己的Windows类,而VS无法创建它的实例。 So now it always shows "Can not create an instance of "ChildWindow"". 因此,现在它始终显示“无法创建“ ChildWindow”的实例”。 This would not be bad, but it marks the hole file as error, and this looks realy ugly. 这样做还不错,但它会将孔文件标记为错误,这看起来确实很丑。

So: I would love to tell him to ignore the ChildWindow error, but show other errors, but don't know how. 所以:我很想告诉他忽略ChildWindow错误,但显示其他错误,但不知道如何。

Thanks for your advice. 谢谢你的建议。

EDIT: To make the things a bit clearer here is a sample of the code: 编辑:为了使事情更清楚一点,这里是代码示例:

<cis:ChildWindow ... />
    .
    .
    .
</cis:ChildWindow>

where cis:ChildWindow is derived from UserElement. 其中cis:ChildWindow从UserElement派生。 Now the preview from VS can't create an instance of childWindow and throws an errror. 现在,VS的预览无法创建childWindow的实例并抛出错误。 If I build the Project everything is fine. 如果我构建项目,一切都很好。

You can right-click on the file in Solution Explorer and choose to Exclude it from the solution. 您可以在解决方案资源管理器中右键单击该文件,然后选择将其从解决方案中排除。 You'll then be able to build your solution and it won't complain about errors in that file. 这样您就可以构建解决方案,并且不会抱怨该文件中的错误。

But that only works if you don't need to use the file to build your solution. 但这仅在不需要使用文件来构建解决方案的情况下才有效。 If you need the file to be included then I'm not aware of any way to achieve what you want, other than commenting out the lines that are causing a problem (other than the obvious solution, which is to fix the actual problem, but I'm guessing there's a good reason you can't do that). 如果您需要包含该文件,那么除了注释出引起问题的行(除了显而易见的解决方案是解决实际问题之外,我不知道有什么方法可以实现您想要的)我猜有一个很好的理由你不能这样做。

Does ChildWindow create objects (or have a DataContext) that require external assemblies, hardware drivers, or anything unusually picky? ChildWindow是否创建需要外部程序集,硬件驱动程序或任何异常挑剔的对象(或具有DataContext)?

If so, and if you can find out which object this is through trial and error, sometimes the following works: 如果是这样,并且您可以通过反复试验找出这是哪个对象,则有时可以进行以下操作:

bool inDesignMode = System.ComponentModel.DesignerProperties.GetIsInDesignMode(this);

if(!inDesignMode)
    InitializePickyDriver();

It's worked for me a few times. 它为我工作了几次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM