如何使用 Caliburn.Micro 和不同的 UserControls 制作 TabControl

How to make TabControl with Caliburn.Micro and diffrent UserControls

我对 TabControl 有疑问,我什至不知道如何开始。

我有一个名为 MainViewModel 的根视图。 Csharp class 看起来像这样:

public class MainWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
    //i have couple of ToggleButtons to load diffrent UserControls, LoadAddNewPage 
    //is one of them
    public void LoadAddNewPage() => this.ActivateItem(new AddNewTaskViewModel(params));
}

我在 MainWindowView.XAML 中有 ToggleButton 正在加载 LoadAddNewTaskPage

<ToggleButton x:Name="LoadAddNewPage"               
            Grid.Column="4"
            Width="50" Height="50" 
            Content="&#xf067;" 
            Foreground="White" 
            BorderThickness="0"  
            BorderBrush="{x:Null}" 
            Background="#FF085078" Margin="20,3,0,3" Grid.ColumnSpan="3">
       <!-- i deleted data triggers here -->
    </ToggleButton>

正如您在上面看到的,它加载 AddNewTaskViewModel 表单以将新项目添加到我的 database/list(或其他)。

AddNewTaskView.xaml 很简单 UserControl 带有文本框等

我的问题是,如何准备我的 LoadAddNewPage 按钮来加载两个 UserControlerTabControl?现在,我正在加载 new AddNewTaskViewModel()(它是 UserControl,它会按照我的意愿正确加载)。如何用 Caliburn.Micro 制作 TabControl 来存储 AddNewTaskViewModelAddNewProjectViewModel?如何在两个不同的 UserControl 之间切换 TabControl?我有一个问题要开始,因为我不知道如何开始这个问题。感谢您的任何建议

编辑

在这里我将展示我的完整 ViewModel

 public class MainWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
    protected override void OnViewLoaded(object view) => Show.LoginBox(this.loggedUser);

    public void LoadUserInfoPage() => this.ActivateItem(new UserInfoViewModel(this.loggedUser));

    public void LoadTaskManagerPage() => this.ActivateItem(new TaskManagerViewModel(this.loggedUser, this.repository));

    public void LoadNotificationsPage() => this.ActivateItem(new NotificationsViewModel(this.repository));

    //here, i want to trigger TabControl with two VMs to choose
    public void LoadAddNewTaskPage() => this.ActivateItem(new AddNewTaskViewModel(this.loggedUser, this.repository));
}

EDIT2

我了解上下文,但我想实现:

制作另一个 Vm class,它将存储我想在我的 TabControl:

中使用的 User Controls
public class TabControlViewModel 
{
    //how to store two VMs that i will use to my TabControl here?
}

并且在 MainViewModel 中:

public class MainWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
    //activate TabControlViewModel that will store AddTaskVM and AddProjectVM
    //this vm will display on my `TabControl` in xaml in `MainWindowView.xaml`
    public void LoadAddNewPage() => this.ActivateItem(new TabControlViewModel(params));
}

添加一个名为 "Items" 的 TabControl 到视图:

<TabControl x:Name="Items" />

...以及另一个 Button 和将另一种类型的 Screen 添加到 Items 集合的方法:

public class MainWindowViewModel  : Conductor<IScreen>.Collection.OneActive
{
    public void LoadAddNewTask() => this.ActivateItemAsync(new AddNewTaskViewModel());
    public void LoadAddNewProject() => this.ActivateItemAsync(new AddNewProjectViewModel());
}