简体   繁体   English

使用caliburn.micro显示2个ViewModel

[英]Displaying 2 ViewModels using caliburn.micro

I am looking to display 2 controls on the screen at the same time and allow them to transition independently from one another. 我希望同时在屏幕上显示2个控件,并允许它们彼此独立过渡。 I am using a Conductor.Collection.AllActive but cannot figure out how to get the List control (a screen called ProductListViewModel) and the detail screen (ProductViewModel) to show up at the same time in the shell. 我正在使用Conductor.Collection.AllActive,但无法弄清楚如何获取List控件(一个名为ProductListViewModel的屏幕)和详细信息屏幕(ProductViewModel)在shell中同时显示。

How do I get them to load into the appropriate ContentControls? 如何让它们加载到适当的ContentControls中?

    <mah:TransitioningContentControl Grid.Row="2" Grid.Column="1" 
        Margin="5"                             
        x:Name="NavigationFrame"/>

    <mah:TransitioningContentControl Grid.Row="2" Grid.Column="2" Margin="5" 
        x:Name="ContentFrame" />

I figured it out and think it is actually very simple. 我想出来并认为它实际上非常简单。 The ViewModel needs an IScreen property per content area in which you want to place an independent view. ViewModel需要在每个要放置独立视图的内容区域中使用IScreen属性。

So, in this case, it would be 所以,在这种情况下,它会

public class ShellViewModel: Screen
{
    private string _title = "Some title";
    private Conductor<IScreen> _listConductor;
    private Conductor<IScreen> _detailConductor;

    public ShellViewModel()
    {
        _listConductor = new Conductor<IScreen>();
        _detailConductor = new Conductor<IScreen>();

        ListFrame = GetContainer().Resolve<ProductListViewModel>();
        DetailFrame = GetContainer().Resolve<ProductViewModel>();
    }

    public string Title { get => _title; set => _title = value; }

    public IScreen ListFrame
    {
        get { return _listConductor.ActiveItem; }
        set {
            _listConductor.ActivateItem(value);
            NotifyOfPropertyChange(nameof(ListFrame));
        }
    }

    public IScreen DetailFrame
    {
        get { return _detailConductor.ActiveItem; }
        set {
            _detailConductor.ActivateItem(value);
            NotifyOfPropertyChange(nameof(DetailFrame));
        }
    }

etc. 等等

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

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