简体   繁体   English

Caliburn.Micro WindowManager找不到视图

[英]Caliburn.Micro WindowManager Cannot find view

I have done some searching and I can't find anyone with my specific problem. 我进行了一些搜索,但找不到任何遇到我特定问题的人。

I have a Caliburn.Micro project and I successfully have a main view with sub-views inside it which is not a problem. 我有一个Caliburn.Micro项目,并且我成功地拥有了一个带有子视图的主视图,这不是问题。 My View Models are in a different assembly to my views. 我的视图模型与我的视图位于不同的程序集中。

This meant I had to override SelectAssemblies to include my view models project: 这意味着我必须重写SelectAssemblies才能包含我的视图模型项目:

protected override IEnumerable<Assembly> SelectAssemblies()
    {
        var assemblies = base.SelectAssemblies().ToList();
        assemblies.Add(typeof(OrderViewModel).Assembly);

        return assemblies;
    }

Now, this is where my confusion starts. 现在,这是我困惑的起点。 I successfully have a OrderView showing the OrderViewModel. 我成功地显示了OrderViewModel的OrderView。 Inside that there is a KeyboardViewModel with a KeyboardView. 里面有一个带有KeyboardView的KeyboardViewModel。 This all works fine so caliburn is finding the right assemblies etc. 这一切都很好,所以caliburn正在寻找合适的组件等。

However when I come to use the window manager to display a new view/viewmodel which is passed into the order view. 但是,当我开始使用窗口管理器来显示新的视图/视图模型时,该视图/视图模型将传递到订单视图中。 I am getting a screen with the text "Cannot find view model for XX.ViewModels.Model." 我得到一个带有文本“无法找到XX.ViewModels.Model的视图模型”的屏幕。

This is my OrderViewModel 这是我的OrderViewModel

[Export(typeof(OrderViewModel))]
public class OrderViewModel : Screen
{
        private readonly IWindowManager windowManager;
        private ISession session;

        [ImportingConstructor]
        public OrderViewModel(IWindowManager windowManager, KeyboardViewModel keyboardViewModel)
        {
            TillDatabase.CreateInstance(ApplicationConfiguration.Instance.DatabaseConnectionString);
            this.windowManager = windowManager;
            this.Keyboard = keyboardViewModel;
            this.Keyboard.Order = this;
            this.Keyboard.Home();
        }


        public void ChangePriceBand()
        {
            windowManager.ShowWindow(new PriceBandSelectionViewModel(this));
        }

}

The thing is, I even tried this in ChangePriceBand 问题是,我什至在ChangePriceBand中尝试过

 windowManager.ShowWindow(new OrderViewModel(this.windowManager, new KeyboardViewModel()));

And this gets the same error. 并得到相同的错误。 Even though a view has already been associated with the OrderViewModel previously!! 即使以前视图已经与OrderViewModel关联!

This is the PriceBandSelectionViewModel just in case. 这是PriceBandSelectionViewModel以防万一。

[Export(typeof(PriceBandSelectionViewModel))]
public class PriceBandSelectionViewModel : Screen
{
    private OrderViewModel order;

    [ImportingConstructor]
    public PriceBandSelectionViewModel(OrderViewModel order)
    {
        this.order = order;
    }

    public ObservableCollection<PriceBandButtonViewModel> Buttons
    {
        get
        {
            var list = new ObservableCollection<PriceBandButtonViewModel>();
            var priceBands = this.order.Session.QueryOver<Application_Model_PriceBand>().List();
            foreach (var priceBand in priceBands)
            {
                PriceBandButtonViewModel button = new PriceBandButtonViewModel(priceBand, this);
                list.Add(button);
            }
            return list;
        }
    }


    public void ProcessButtonClick(Application_Model_PriceBand button)
    {
        this.order.ChangeCurrentPriceBand(button);
        base.TryClose();
    }

}

I'm just really confused to how Caliburn is setting up my main view, but the window manager isn't even though its the same ViewModel? 我只是对Caliburn如何设置我的主视图感到困惑,但是即使窗口管理器具有相同的ViewModel,它也不是吗?

have you tried to remove OrderViewModel or put a breakpoint there, cant find view error might happen if it encountered error when initialising the exported class 您是否尝试删除OrderViewModel或在其中放置断点,如果初始化导出的类时遇到错误,则可能找不到视图错误

public PriceBandSelectionViewModel()
{
    // this.order = order;
}

or add 或添加

assemblies.Add(typeof(PriceBandSelectionViewModel).Assembly);

This may be the same problem as I am experiencing as described here: Caliburn.Micro HelloWindowManager Sample - View location not working 这可能是与我在此处描述的问题相同的问题: Caliburn.Micro HelloWindowManager示例-视图位置不起作用

To see if it is the same problem, try changing the call from 要查看是否存在相同的问题,请尝试从更改呼叫

windowManager.ShowWindow(new PriceBandSelectionViewModel(this)); 

to

windowManager.ShowDialog(new PriceBandSelectionViewModel(this));.  

In my case, ShowDialog was able to locate the view no problem, but ShowWindow and ShowPopup were not. 在我的情况下,ShowDialog能够找到视图没有问题,但是ShowWindow和ShowPopup却没有。

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

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