本文是小编为大家收集整理的关于"设计模式 "预处理程序指令的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我有
现在,问题是我不能仅使用预处理器指令就设计时间"评论". 现在,我尝试了(对于vb.net)以下 这个...有效,现在在设计师中没有问题显示. 现在我恐怕无法正确调试这个组件. 所以,我正在寻找解决方法àla 有类似的东西吗? 您无法通过预处理器实现这一目标.这是因为您可以在VS之外运行调试可执行文件(尝试一下,双击在调试模式下由VS生成的EXE). 无论如何,有一个运行时(不是基于预处理器的)属性可能会有所帮助: 这些网页将有所帮助,并具有在运行时检查设计模式的其他方法: -us/library/c58hb4bw(vs.71).aspx http://weblogs.net/fmarguerie/档案/2005/03/23/395658.aspx IDE不会重建您的代码以向设计师展示.它使用您已经构建的二进制文件.因此,预处理器指令无济于事. 由于您提到myWpfComponent_ItsEvent,我认为这是一个WPF问题.在WPF中,您可以使用 >. 使用: 请注意,"此"标识符可以是任何依赖项#If Not Debug Then
Private Sub myWpfComponent_ItsEvent(sender, args) Handles myWpfComponent.ItsEvent
...
#End If
#If Not DESIGN_TIME Then
#End If
推荐答案
if (System.ComponentModel.LicenseManager.UsageMode ==
System.ComponentModel.LicenseUsageMode.Designtime)
其他推荐答案
其他推荐答案
if (!DesignerProperties.GetIsInDesignMode(this))
{
//Code to not execute in design mode
}
问题描述
I have a problem on displaying a component in Designer.
I identified the "bad" code that the designer does not like.
Now, the problem is that I can't "comment" it for design time only using preprocessor directives.
Now, I tried (for VB.NET) the following
#If Not Debug Then Private Sub myWpfComponent_ItsEvent(sender, args) Handles myWpfComponent.ItsEvent ... #End If
this... worked, and now it is displayed without problems in the designer.
The problem now that I am afraid do not be able to debug properly this component.
So, I am searching for a workaround à la
#If Not DESIGN_TIME Then #End If
Is there something similar?
推荐答案
You cannot achieve this through the preprocessor. This is because you can run a debug executable outside of VS (try it, double click on the EXE generated by VS under debug mode).
Anyway, there is a runtime (not preprocessor based) property that might help:
if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
These web pages will help and have other methods of checking for design mode at runtime:
http://msdn.microsoft.com/en-us/library/c58hb4bw(vs.71).aspx
http://weblogs.asp.net/fmarguerie/archive/2005/03/23/395658.aspx
其他推荐答案
The IDE doesn't rebuild your code to show the designer. It uses the binary that you've already built. So a preprocessor directive won't help.
Since you mention myWpfComponent_ItsEvent, I assume this is a WPF question. In WPF, you detect design mode by using GetIsInDesignMode.
其他推荐答案
Use:
if (!DesignerProperties.GetIsInDesignMode(this)) { //Code to not execute in design mode }
Note that "this" identifier can be any DependencyObject