【发布时间】:2018-09-02 20:34:30
【问题描述】:
我一直在关注 Winforms 教程并使用 Caliburn.Micro 将其转换为 WPF 和 MVVM。但是,在 winforms 教程中,它调用了一个新表单。
CreatePrizeForm frm = new CreatePrizeForm();
frm.Show;
我想我可以使用 Caliburn.Micro ActivateItem 来做类似的事情。我已经包含了一些我的实验代码。
我的 ShellViewModel
public class ShellViewModel : Conductor<object>
{
public void LoadFormOne()
{
MessageBox.Show("You are about to activate FirstChildViewModel");
ActivateItem(new FirstChildViewModel());
}
public void LoadFormTwo()
{
MessageBox.Show("You are about to activate SecondChildViewModel");
ActivateItem(new SecondChildViewModel());
}
}
我的贝壳视图
<Window x:Class="ConductorTest.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ConductorTest"
mc:Ignorable="d"
Title="ShellViewModel" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="1" x:Name="LoadFormOne" Content="Load Form One" />
<Button Grid.Column="1" Grid.Row="3" x:Name="LoadFormTwo" Content="Load Form Two" />
</Grid>
</Window>
一个 ChildViewModel
public class FirstChildViewModel : Screen
{
public FirstChildViewModel()
{
}
}
一个子视图
<Window x:Class="ConductorTest.FirstChildView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ConductorTest"
mc:Ignorable="d"
Title="FirstChildView" Height="450" Width="800">
<Grid>
<TextBlock>You are now in First Child View</TextBlock>
</Grid>
</Window>
所以我的想法是,如果我点击 LoadFormOne 按钮,它就会执行,
ActivateItem(new FirstChildViewModel());
然后会新建一个 FirstChildViewModel(),类似于
DisplayRootViewFor<ShellViewModel>();
在标准的 bootstrapper.cs 中,然后会启动一个新的 WPF 表单。
但显然不是。
我缺少什么或者 Caliburn.Micro 没有提供一种简单的方法来做到这一点?
谢谢
【问题讨论】:
-
它有一个窗口管理器。看看caliburnmicro.com/documentation/window-manager
-
已删除评论
标签: c# wpf mvvm dialog caliburn.micro