您好,我在Caliburn微中创建了simpel MDI,类似于:http://devlicio.us/blogs/rob_eisenberg/archive/2010/10/19/caliburn-micro-soup-to-nuts-part-6c-simple-mdi-with-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从列表中,当标签项目停用。
Shell视图模型类:
[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);
}
}
}Shell视图:
<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视图模型类上的选项卡项视图模型类发布消息来实现此行为。
但我想用一些更简单的东西。例如,选项卡项可以在停用时调用shell视图方法。
有什么建议吗?谢谢
发布于 2011-02-09 04:17:53
继承TabChatViewModel的Screen类(由框架提供)定义了TryClose方法。此方法尝试通过询问其父屏幕(在本例中为ChatShellViewModel conductor)或要求关闭视图来关闭当前屏幕。
因此,您所需要做的就是在调用close操作时从TabChatViewModel中调用TryClose()。
https://stackoverflow.com/questions/4924582
复制相似问题