FCin FCin - 2 months ago 21
C# Question

Displaying multiple screens in conductor doesn't work

I want to display a couple of screens at the same time. Displaying only one screen works fine, but when I switch my conductor to

Conductor<DMChartBase>.Collection.AllActive
and add another item, it still renders only one item.

public class DocumentViewModel : Conductor<DMChartBase>.Collection.AllActive
{
public ChartLegendViewModel ChartLegendVm { get; set; }

public DocumentViewModel()
{
ChartLegendVm = new ChartLegendViewModel();
ActivateItem(ChartLegendVm);
}

public void ChangeChart(DMChartBase chart, Column[] columns)
{
ActivateItem(chart);
Items.Last().Init(columns);
Items.Refresh();
}
}


And
DocumentView
:

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


I cannot find any reason why this doesn't work. Any ideas?

EDIT:
My code structure looks like this:

public class ShellViewModel : Screen
public class DocumentViewModel : Conductor<DMChartBase>.Collection.AllActive
public class ChartLegendViewModel : ChartDecorator
public abstract class ChartDecorator : DMChartBase
public abstract class DMChartBase : Screen


DocumentView:

<UserControl ...>
<Grid>
<ItemsControl x:Name="Items">
</Grid>
</UserControl>


ChartLegendView:

<UserControl ....>
<ListView>
<ListViewItem Content="First value"></ListViewItem>
<ListViewItem Content="Second value"></ListViewItem>
<ListViewItem Content="Third value"></ListViewItem>
</ListView>
</UserControl>


Bootstrapper:

protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<ShellViewModel>()
}


EDIT:
I figured it out!
Previously I wanted to instantiate Chart and Legend separately which is wrong.
DocumentViewModel
should only be responsible for instantiating
ChartDecorator
. Inside
ChartDecorator
I can create as many decorator classes as I want (such as ChartLegendViewModel) and they all get drawn.

Answer

IoC isn't used at all? Secondly can you show us bootstrapper and XAML would help alittle. Are these items in a separate library? Normally Conductor uses a Screen or IScreen to have access to the "screens" lifetime. So unless DMChartBase inherits screen(IScreen) I don't think you will get an activation...

//MEF IoC Container -- CM Built-in
[Export(typeof(MainWindowViewModel))]
public class MainWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
    [ImportingConstructor]
    public MainWindowViewModel([ImportMany]IEnumerable<IScreen> screens)
    {
        DisplayName = "COmposition Example - CM";


        Items.AddRange(screens.Reverse());
    }

    protected override void OnActivate()
    {
        ActivateItem(Items[0]);
    }
}

as an example... It shows all of them but only one is Active if you change it to AllActive they all would be active "can inter-communicate" but they aren't visible due to constraints of the control, used for this case (tab control) but if it was changed to an itemscontrols you still need to some work since the view wouldn't know how to deal with the binding of the view to the viewmodel

Comments