Can I use Caliburn Micro - Conductor<t> and Conductor<t>.Collection.AllActive in the same ShellViewModel

514 Views Asked by At

I'm trying to create a sort of Dashboard using MVVM and Caliburn Micro. Part of this Dashboard will be a number of 'Widgets' that show various sets of information, these do not allow any user input but may change depending on input elsewhere in the app. Each individual widget is a View/ViewModel UserControl displayed using Conductor.Collection.AllActive and an ItemsControl containg a ContentControl. This is working great. Now the problem... I also want to display on the ShellView another UserControl (which particular UserControl is determined by the user clicking a button). This userControl is where the data can be altered, its basically going to be a New/Edit data screen. If I just add a Conductor ActivateItem(ViewModel) in the ShellViewModel, Caliburn ignores it, if I implement the single item base class I get'Error CS1721 Class 'ShellViewModel' cannot have multiple base classes: 'Conductor.Collection.AllActive' and 'Conductor' So the question is (I think).. Is it possible to combine multiple Conductor base classes in a single view?

ShellViewModel code is

public class ShellViewModel : Conductor<Screen>.Collection.AllActive /*, Conductor<Screen>*/  /*This fails!*/
    {
        public ShellViewModel(RentalProperties_ViewModel rentalProperties_ViewModel, TestScreenViewModel testScreenViewModel,
            AnotherTestScreenViewModel anotherTestScreenViewModel)
        {
            this.Items.Add(rentalProperties_ViewModel);
            this.Items.Add(testScreenViewModel);
            this.Items.Add(anotherTestScreenViewModel);
        }

    public void ShowTestView() /* This is the method I want to add, at the moment Caliburn ignores it or at least ignores the ActivateItem part */
    {
        ActivateItem(new DataEditScreenViewModel());
    }

Working ShellView XAML is

        <Grid Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="1" Grid.RowSpan="3"
          Background="Aquamarine" >
        <ScrollViewer>
        <ItemsControl x:Name="Widgets" ItemsSource="{Binding Items}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="CadetBlue" BorderThickness="2" Margin="10">
                        <StackPanel Orientation="Horizontal" >
                            <ContentControl cal:View.Model="{Binding}"
                                            VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                                            IsTabStop="False"/>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        </ScrollViewer>
    </Grid>

This is the XAML I want to add

<ContentControl Grid.Row="2" Grid.Column="2"
                        x:Name="ActiveItem"/>

Grateful thanks in advance

0

There are 0 best solutions below