Caliburn.Micro - ShowDialog的()如何关闭对话框? [英] Caliburn.Micro - ShowDialog() how to close the dialog?

查看:1872
本文介绍了Caliburn.Micro - ShowDialog的()如何关闭对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:

新信息,只是得到了一个记录器的工作(!老实说,我不知道厘米有一个)和i M给予尝试使用此邮件时 TryClose()

New Information, just managed to get a logger working (I honestly had no idea cm had one!) and i'm given this message when attempting to use TryClose().

TryClose requires a parent IConductor or a view with a Close method or IsOpen property



我一直停留在这个数天的现在,并研究止跌回升零,我想以前张贴问题关于这个问题,但让我以为我没有正确的字呢它没有收到任何答复。

I have been stuck on this for a number of days now, and research has turned up zero, I tried posting a question previously about this issue but it received no answers so i assume I didn't word it correctly.

我有一个观点和视图模型的内容查看/型号有下面的代码在其中:

I have a view and viewmodel ContentView/Model which has the following code in them:

内容查看

<MenuItem Header="New Project" x:Name="OpenProject" cal:Message.Attach="[Event Click] = [Action NewProject()]"/>



ContentViewModel

public void NewProject()
    {
        NewProjectViewModel viewModel = new NewProjectViewModel(_projectManager);
        _windowManager.ShowWindow(viewModel);
        //If the result is true, we have a new project, otherwise they cancelled the window.
        if (viewModel.Result)
        {
            Project newP = new Project(0, viewModel.ProjectNo, viewModel.ProjectName, 0, 0);
            _projectManager.Insert(newP);
        }
    }

和视图模型 NewProjectViewModel 有以下几点:

and the viewmodel NewProjectViewModel has the following:

 public void Create()
    {
        this.Result = true;
        TryClose(true);
    }



这就是所谓的在同一如以前使用的一个message.attach 确定按钮对话框。

然而,问题是, TryClose()总是无法关闭对话框,并且我没有caliburn.micro的来源,我不能在 TryClose调试()但是这样做( GetView()作为窗口).Close()也失败了,因为 GetView()始终返回null。

However the issue is that TryClose() always fails to close the dialog, and as i don't have the source of caliburn.micro i can't debug inside TryClose() however doing (GetView() As Window).Close() also fails because GetView() always returns null.

我在一个完全不知如何我可以关闭此对话框,因此任何帮助或建议,将不胜感激。

I'm at a complete loss as to how i can close this dialog, so any help or suggestions would be greatly appreciated.

修改
由于我似乎越来越对这个没有答案,那里的前面的问题做的,我会认为我有信息丢失。在试图理解我认为它可能有一些与使用视图第一种方法的问题。

Since i seem to be getting no answers on this, where as previous questions do, I'll assume i have information missing. In an attempt to understand the issue i think it may have something to with using the view first approach.

NewProjectView 我有以下

             xmlns:cal="http://www.caliburnproject.org"
         cal:Bind.Model="ShippingClient.ViewModels.NewProjectViewModel"

此用于将视图模型结合,而不是为自动方式通常使用,也许这就是为什么 GetView()返回null?

This is used to bind the viewmodel rather than the automatic way that is usually used, perhaps this is why GetView() returns null?

推荐答案

你要绝对踢自己:

删除 CAL:Bind.Model CAL:View.Model 绑定...

如果您正在使用视图模型优先(即你正在创建一个视图模型,并将其显示使用窗口管理器或导体)所有的胶合视图模型到视图为您做CM绑定的东西。

If you are working ViewModel-First (i.e. you are creating a viewmodel and showing it using WindowManager or in a conductor) all the binding stuff that glues the viewmodel to the view is done for you by CM.

在这种情况下,你不应该使用任何View-首先绑定。你基本上做的是newing你的VM的另一个实例,并绑定到你的观点...所以你有后台的两个的ViewModels,一是有线起来好听,但没有绑定任何更多的,和非接线实例,这绑定到您的看法,但不知道导体。

In this case you shouldn't use any View-First bindings. What you are essentially doing is newing up another instance of your VM and binding that to your view... so you have two viewmodels in the background, one wired up nicely but not bound any more, and a non-wired up instance which is bound to your view but doesn't know about the conductor.

只是删除的任何绑定到视图模型在您的视图,它会所有的工作!

Just remove any bindings to the viewmodel in your view and it will all work!

这篇关于Caliburn.Micro - ShowDialog的()如何关闭对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆