shell caliburn micro或其他MVVM框架中更活跃的屏幕/视图
如果我使用caliburn micro,是否可能在一个外壳中有更多活动屏幕/视图 类似于此,shell视图-wpf窗口的代码:shell caliburn micro或其他MVVM框架中更活跃的屏幕/视图,shell,mvvm,screen,caliburn.micro,Shell,Mvvm,Screen,Caliburn.micro,如果我使用caliburn micro,是否可能在一个外壳中有更多活动屏幕/视图 类似于此,shell视图-wpf窗口的代码: <ContentControl x:Name="ActiveItem_1" Grid.Row=1/> <ContentControl x:Name="ActiveItem_2" Grid.Row=2/> <ContentControl x:Name="ActiveItem_9" Grid
<ContentControl x:Name="ActiveItem_1" Grid.Row=1/>
<ContentControl x:Name="ActiveItem_2" Grid.Row=2/>
<ContentControl x:Name="ActiveItem_9" Grid.Row=9/>
感谢您的建议,或者在哪个MVVM中可能实现此功能?是的。这是可能的与
Conductor<T>.Collection.AllActive
Conductor.Collection.AllActive
见文件页
我相当肯定Caliburn.Micro会负责剩下的部分,但我目前无法测试 如果是AllActive conductor,您将继承ShellViewModel中的
项
集合。调用ActivateItem(vm)
时,视图模型将被添加到项目
集合中,调用DeactivateItem(vm,close:true)
时,视图模型将被删除。然后在ShellView.xaml中,您可以将项
(视图模型集合)绑定到项控件
MyView.xaml
<UserControl x:Class="AllActive_Test.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Text="{Binding Path=MyProperty}"/>
</Grid>
</UserControl>
<Window x:Class="AllActive_Test.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.caliburnproject.org"
Width="300" Height="300">
<Grid Background="White">
<ItemsControl ItemsSource="{Binding Path=Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl cal:View.Model="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
ShellView.xaml
<UserControl x:Class="AllActive_Test.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Text="{Binding Path=MyProperty}"/>
</Grid>
</UserControl>
<Window x:Class="AllActive_Test.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.caliburnproject.org"
Width="300" Height="300">
<Grid Background="White">
<ItemsControl ItemsSource="{Binding Path=Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl cal:View.Model="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
ShellViewModel.cs
class MyViewModel : Screen
{
private int myVar;
public int MyProperty
{
get
{
return myVar;
}
set
{
myVar = value;
this.NotifyOfPropertyChange(() => MyProperty);
}
}
}
public class ShellViewModel : Conductor<Screen>.Collection.AllActive, IShell
{
public ShellViewModel()
{
for (int i = 0; i < 3; i++)
{
MyViewModel vm = new MyViewModel();
vm.MyProperty = i;
ActivateItem(vm);
}
}
}
公共类ShellViewModel:Conductor.Collection.AllActive,IShell
{
公共ShellViewModel()
{
对于(int i=0;i<3;i++)
{
MyViewModel vm=新的MyViewModel();
vm.MyProperty=i;
激活肽(vm);
}
}
}
谢谢,您能给我提供一些简单的示例,说明如何使用它Conductor.Collection.AllActive吗?一些用于shell、视图模型和view-XAML的代码。感谢您查看CM下载附带的HelloScreens示例。HelloScreens示例中没有包含AllActiv的示例。有人能给我介绍一个使用Conductor.Collection.AllActiv的示例,其中包括不同的屏幕,如以下也是有趣的合成示例: