开发者

Is there an attribute that ignores a method on design-time?

开发者 https://www.devze.com 2022-12-17 12:58 出处:网络
Something like: <DesignTimeHidden()开发者_如何学编程> _ Private Sub UserControl_IsVisibleChanged(sender As Object, _

Something like:

<DesignTimeHidden()开发者_如何学编程> _
Private Sub UserControl_IsVisibleChanged(sender As Object, _
    e As DependencyPropertyChangedEventArgs) Handles Me.IsVisibleChanged

End Sub


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 is not set until after construction, so is not reliable in the constructor or methods called from the constructor).

  • For WPF components, call DesignerProperties.IsInDesignMode(this).

0

精彩评论

暂无评论...
验证码 换一张
取 消