嗨,我在 caliburn micro 中创建了 simpel MDI,如下所示: http ://devlicio.us/blogs/rob_eisenberg/archive/2010/10/19/caliburn-micro-soup-to-nuts-part-6c-simple-mdi-与-screen-collections.aspx。
每个选项卡项都由 ID 标识(ID 是 DisplayName 属性)。我只需要为每个 id.Tab 项打开单个选项卡项是用户控件。
选项卡项视图模型类在这里:
[Export(typeof(ITabChatViewModel))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class TabChatViewModel : Screen, IViewModelIdentity,
IPartImportsSatisfiedNotification,
ITabChatViewModel, IHandle<IRp>, IHandle<IDetailData>
{...}
因此,如果我在 shell 中激活选项卡项,我会将选项卡 ID 存储在列表中。
当标签项停用时,我需要从列表中删除标签 ID。
外壳视图模型类:
[Export(typeof(IChatShellViewModel))]
public class ChatShellViewModel :
Conductor<IScreen>.Collection.OneActive,
IChatShellViewModel
{
//consist active tab item
List<string> ActiveTabItems { get; set; }
public ChatShellViewModel()
{
ActiveTabItems=new List<string>();
}
public void OpenChatTab(IScreen screen)
{
if(!ActiveTabItems.Contains(screen.DisplayName))
{
ActivateItem(screen);
ActiveTabItems.Add(screen.DisplayName);
}
}
}
外壳视图:
<Window x:Class="Spirit.Views.ChatShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
Height="545"
Width="680">
<DockPanel>
<TabControl x:Name="Items">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}"
VerticalAlignment="Center"/>
<Image Source="/images/icons/close.png"
Margin="8,4,4,4"
Height="16"
Width="16"
HorizontalAlignment="Right"
VerticalAlignment="Center"
cal:Message.Attach="[Event MouseLeftButtonDown]=[Action CloseItem($dataContext)]"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</DockPanel>
</Window>
我可以使用事件聚合器类来实现此行为,并在选项卡项停用时从 shell 视图模型类上的选项卡项视图模型类发布消息。
但我想使用更简单的东西。例如选项卡项在停用时可以调用外壳视图方法。
有什么建议吗?谢谢