mahapps metro showMessageAsync错误:“对象引用未设置为对象的实例”

时间:2014-03-03 14:14:08

标签: c# mahapps.metro

我有这个方法

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

我从MetroWindow的cuntructor调用。但是我得到了这个错误:

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");

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

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