【问题标题】:Displaying 2 ViewModels using caliburn.micro使用 caliburn.micro 显示 2 个 ViewModel
【发布时间】:2019-05-09 13:19:39
【问题描述】:

我希望同时在屏幕上显示 2 个控件,并允许它们相互独立地转换。我使用的是 Conductor.Collection.AllActive,但无法弄清楚如何让 List 控件(名为 ProductListViewModel 的屏幕)和详细信息屏幕 (ProductViewModel) 同时显示在 shell 中。

如何让它们加载到适当的 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" />

【问题讨论】:

  • 你能发一下你的ViewModel吗?这只是XAML

标签: c# caliburn.micro


【解决方案1】:

我想通了,觉得其实很简单。 ViewModel 需要一个 IScreen 属性,每个内容区域都需要在其中放置独立视图。

所以,在这种情况下,它会是

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

等等

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-06
    • 2012-06-20
    • 2014-05-09
    • 2013-03-21
    • 2022-10-18
    • 2011-05-01
    • 2013-10-22
    • 1970-01-01
    相关资源
    最近更新 更多