是否有一个属性在设计时忽略方法?
像这样的东西:
<DesignTimeHidden()> _
Private Sub UserControl_IsVisibleChanged(sender As Object, _
e As DependencyPropertyChangedEventArgs) Handles Me.IsVisibleChanged
End Sub
Something like:
<DesignTimeHidden()> _
Private Sub UserControl_IsVisibleChanged(sender As Object, _
e As DependencyPropertyChangedEventArgs) Handles Me.IsVisibleChanged
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想要一个方法,如果在设计时调用,则会被忽略,但仍然可以在运行时调用。
对于属性来说这是不可能的。但是,您的方法代码可以检查它是否在设计时被调用,然后返回而不执行任何操作。如何执行此操作取决于您的环境。
对于 WinForms 或
ASP.NET 控件,检查
DesignMode
属性(注意这是直到施工完成后才设置,所以
在构造函数中不可靠或者
从构造函数调用的方法)。
对于 WPF 组件,请调用
DesignerProperties.IsInDesignMode(this)
。It sounds like you want a method which, if called at design-time, is ignored, but can still be called at run-time.
This is not possible with an attribute. However your method code can check if it is being called at design time and return without doing anything. How you do this depends on your environment.
For components such as WinForms or
ASP.NET controls, check the
DesignMode
property (note this isnot set until after construction, so
is not reliable in the constructor or
methods called from the constructor).
For WPF components, call
DesignerProperties.IsInDesignMode(this)
.