繁体   English   中英

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

[英]mahapps metro showMessageAsync error: “ Object reference not set to an instance of an object”

我有这种方法

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

我该如何解决?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM