Shell caliburn micro或另一个MVVM框架中有更多活动的屏幕/视图 [英] more active screens / views in shell caliburn micro or another MVVM framework
问题描述
如果我使用caliburn micro,有可能在一个外壳中拥有更多活动屏幕/视图?
It is possible have more active screen / view in one shell if I am using caliburn micro ?
类似这样的代码,用于shell视图-wpf窗口:
Something like this, code for shell view - wpf window:
<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中可行?
Thank you for advice, or in which MVVM this possible?
推荐答案
对于AllActive导体,您将在ShellViewModel中继承 Items
集合.调用 ActivateItem(vm)
时,视图模型将添加到 Items
集合中;调用 DeactivateItem(vm,close:true)
时,视图模型将被删除.然后,在ShellView.xaml中,您可以将 Items
(视图模型的集合)绑定到 ItemsControl
.
In case of AllActive conductor you will have inherited Items
collection in your ShellViewModel. When calling ActivateItem(vm)
View Model will be added into Items
collection and when calling DeactivateItem(vm, close: true)
- removed. Then in ShellView.xaml you can bind Items
(collection of View Models) to ItemsControl
.
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>
MyViewModel.cs
class MyViewModel : Screen
{
private int myVar;
public int MyProperty
{
get
{
return myVar;
}
set
{
myVar = value;
this.NotifyOfPropertyChange(() => MyProperty);
}
}
}
ShellView.xaml
<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
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);
}
}
}
这篇关于Shell caliburn micro或另一个MVVM框架中有更多活动的屏幕/视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!