Caliburn Micro Conductor.Collection.AllActive 不工作
Caliburn Micro Conductor.Collection.AllActive not working
我尝试在使用 Caliburn Micro 和 Conductor.Collection.AllActive
的应用程序中激活多个 windows
遵循的步骤:
继承自 Conductor.Collection.AllActive
的 MainHomeViewodel
1) 创建 属性
public ExploreViewModel Explorer {
get; private set;
}
2) 创建了名为 属性 name
的 ContentControl
<ContentControl x:Name="Explorer" />
3) 使用 属性
激活视图模型
Explorer = new ExplorerViewModel();
ActivateItem(Explorer );
执行上述代码后,它会实例化 ExplorerViewModel,但不会转到 View 的构造函数或显示 View。
以上实施有任何问题,或者我需要做更多的事情来激活项目。
请帮忙!
谢谢。
编辑
public class MainHomeWindowViewModel : Conductor<IScreen>.Collection.AllActive
{
protected override void OnInitialize()
{
base.OnInitialize();
ShowExplorer();
}
public void ShowExplorer()
{
Explorer = new ExplorerViewModel();
ActivateItem(Explorer );
}
}
Conductor.Collection.AllActive
使用 Items
属性。如果你想一次显示多个屏幕,你必须将它们添加到 Items
属性.
然后,由于您的视图存储在 Items
属性 中,您希望将视图绑定到 Items
。这是一个例子:
指挥:
public class ShellViewModel : Conductor<IScreen>.Collection.AllActive
{
public ShellViewModel()
{
Items.Add(new ChildViewModel());
Items.Add(new ChildViewModel());
Items.Add(new ChildViewModel());
}
}
Conductor 视图(注意,因为我们显示了我们想要使用的项目集合 ItemsSource
而不是 ContentControl
):
<Grid>
<StackPanel>
<ItemsControl x:Name="Items"></ItemsControl>
</StackPanel>
</Grid>
子屏幕:
public class ChildViewModel : Screen
{
}
子视图:
<Grid>
<Border Width="50" Height="50" BorderBrush="Red" BorderThickness="5"></Border>
</Grid>
编辑:关于评论中的讨论,以下是如何使用 IWindowManager
显示多个 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();
}
}
我尝试在使用 Caliburn Micro 和 Conductor.Collection.AllActive
的应用程序中激活多个 windows遵循的步骤:
继承自 Conductor.Collection.AllActive
的 MainHomeViewodel1) 创建 属性
public ExploreViewModel Explorer {
get; private set;
}
2) 创建了名为 属性 name
的 ContentControl<ContentControl x:Name="Explorer" />
3) 使用 属性
激活视图模型Explorer = new ExplorerViewModel();
ActivateItem(Explorer );
执行上述代码后,它会实例化 ExplorerViewModel,但不会转到 View 的构造函数或显示 View。
以上实施有任何问题,或者我需要做更多的事情来激活项目。
请帮忙!
谢谢。
编辑
public class MainHomeWindowViewModel : Conductor<IScreen>.Collection.AllActive
{
protected override void OnInitialize()
{
base.OnInitialize();
ShowExplorer();
}
public void ShowExplorer()
{
Explorer = new ExplorerViewModel();
ActivateItem(Explorer );
}
}
Conductor.Collection.AllActive
使用 Items
属性。如果你想一次显示多个屏幕,你必须将它们添加到 Items
属性.
然后,由于您的视图存储在 Items
属性 中,您希望将视图绑定到 Items
。这是一个例子:
指挥:
public class ShellViewModel : Conductor<IScreen>.Collection.AllActive
{
public ShellViewModel()
{
Items.Add(new ChildViewModel());
Items.Add(new ChildViewModel());
Items.Add(new ChildViewModel());
}
}
Conductor 视图(注意,因为我们显示了我们想要使用的项目集合 ItemsSource
而不是 ContentControl
):
<Grid>
<StackPanel>
<ItemsControl x:Name="Items"></ItemsControl>
</StackPanel>
</Grid>
子屏幕:
public class ChildViewModel : Screen
{
}
子视图:
<Grid>
<Border Width="50" Height="50" BorderBrush="Red" BorderThickness="5"></Border>
</Grid>
编辑:关于评论中的讨论,以下是如何使用 IWindowManager
显示多个 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();
}
}