开发者

I'm Getting Cannot set Visibility or call Show, ShowDialog Exception

I'm using WAF (Wpf Application Framework) to create a dialog as shown in the ModelView sample application. I am trying to put up a simple AboutBox by mirroring the code for putting up the CreateEmailAccountWizard dialog box. My About box shows up fine the fir开发者_JS百科st time, but when I call it again from the menu, it gives me the following exception:

Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.

First, I don't know what this message means. Second, what am I doing wrong? The sample application doesn't throw this exception when you close and reopen the CreateEmailAccountWizard dialog box. My code is nearly identical to it. Any help would be greatly appreciated.


Never mind. Found the source of the problem. I was creating a singleton from MEF and it was causing the same dialog instance to run twice. I solved the issue by doing the following:

        var shellView = _container.GetExportedValue<IShellView>();
        _aboutDialogViewModel = _container.GetExportedValue<AboutDialogViewModel>();
        _aboutDialogViewModel.ShowDialog(shellView);

I also had to set the MEF attribute on the class to tell it to not use a singleton:

[Export, PartCreationPolicy(CreationPolicy.NonShared)]
public class AboutDialogViewModel : ViewModel<IDialogView>
{
    [ImportingConstructor]
    public AboutDialogViewModel(IDialogView view) : base(view)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜