Vyasdev Meledath
Vyasdev Meledath

Reputation: 9016

Caliburn Micro Conductor.Collection.AllActive not working

I have tried to activate multiple windows in application using Caliburn Micro with Conductor.Collection.AllActive

Steps Followed:

Inhertited MainHomeViewodel from Conductor.Collection.AllActive

1)created property

public ExploreViewModel Explorer {
   get; private set;  
 }

2) Created ContentControl with name as property name

<ContentControl x:Name="Explorer" />

3)Activated viewmodel with property

Explorer = new ExplorerViewModel();
ActivateItem(Explorer );

After execution of above mentioned code its instantiating ExplorerViewModel but doesnt go to View's constructor or showing View .

Any problem with above implementation or do i need to do anything more to activate item.

Please Help!

Thanks.

EDIT

    public class MainHomeWindowViewModel : Conductor<IScreen>.Collection.AllActive
    {
      protected override void OnInitialize()
      {
       base.OnInitialize();
       ShowExplorer();
       }
        public void ShowExplorer()
        {

            Explorer = new ExplorerViewModel();
            ActivateItem(Explorer );

        }
}

Upvotes: 1

Views: 1670

Answers (1)

FCin
FCin

Reputation: 3915

Conductor.Collection.AllActive uses Items property. If you want to display multiple Screens at once, you have to add them to Items property.

Then, because your views are stored in Items property, you want to bind your view to Items. This is an example:

Conductor:

public class ShellViewModel : Conductor<IScreen>.Collection.AllActive
{
    public ShellViewModel()
    {
        Items.Add(new ChildViewModel());
        Items.Add(new ChildViewModel());
        Items.Add(new ChildViewModel());
    }
}

Conductor view (note, because we show collection of items we want to use ItemsSource not ContentControl):

<Grid>
    <StackPanel>
        <ItemsControl x:Name="Items"></ItemsControl>
    </StackPanel>
</Grid>

Child screen:

public class ChildViewModel : Screen
{
}

Child view:

<Grid>
    <Border Width="50" Height="50" BorderBrush="Red" BorderThickness="5"></Border>
</Grid>

EDIT: Regarding discussion in comments, here is how you can use IWindowManager to show multiple windows:

public class ShellViewModel : Screen
{

    public ShellViewModel(IWindowManager windowManager)
    {
        var window1 = new ChildViewModel();
        var window2 = new ChildViewModel();

        windowManager.ShowWindow(window1);
        windowManager.ShowWindow(window2);

        window1.TryClose();
    }
}

Upvotes: 6

Related Questions