我正在使用WPF。我有一个静态类,执行一些在设计模式下不可用的设置。这个构造函数被一个窗口在设计模式下调用,导致抛出异常。
如何在静态方法中检测设计模式,以便调用适当的设计模式行为?
推荐的方法对于静态方法不起作用。
编辑:
静态构造函数是从XAML中调用的,因此我无法有条件地调用它(除非我将调用移动到代码后备中,但我想避免这样做)。
在窗口中:<Window ... HelpProvider.Keyword="some_help_topic.html">
在类中:
static HelpProvider()
{
// Load the .chm file from an application setting (this fails at design time)
// Add a WPF command binding
}
DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow)
,但实际上我不知道这是否适用于你的奇怪情况。 - Akku