簡體   English   中英

使用caliburn.micro顯示2個ViewModel

[英]Displaying 2 ViewModels using caliburn.micro

我希望同時在屏幕上顯示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需要在每個要放置獨立視圖的內容區域中使用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));
        }
    }

等等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM