2

我有这个方法

    public async void setState(int state)
    {
        switch (state)
        {
            default:
                await this.ShowMessageAsync("Title", "Message");
                break;
        }
    }

我是从 MetroWindow 的管理员那里调用的。但我得到这个错误:

An exception of type 'System.NullReferenceException' occurred in MahApps.Metro.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.

在线上

await this.ShowMessageAsync("Title", "Message");

我该如何解决?

4

1 回答 1

4

ShowMessageAsync(...) 使用尚未构造的 overlayBox,因此您需要将调用移到构造函数之外。 https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Controls/MetroWindow.cs#L468

于 2014-03-07T06:43:07.747 回答