首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Caliburn Micro simple MDI

Caliburn Micro simple MDI
EN

Stack Overflow用户
提问于 2011-02-08 01:44:01
回答 1查看 3.1K关注 0票数 1

您好,我在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项目是用户控制。

选项卡项视图模型类如下:

代码语言:javascript
复制
[Export(typeof(ITabChatViewModel))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class TabChatViewModel : Screen, IViewModelIdentity,
    IPartImportsSatisfiedNotification,
    ITabChatViewModel, IHandle<IRp>, IHandle<IDetailData>
{...}

因此,如果我在shell中激活选项卡项,我会将选项卡ID存储在列表中。

我需要一些东西删除标签ID从列表中,当标签项目停用。

Shell视图模型类:

代码语言:javascript
复制
[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视图:

代码语言:javascript
复制
<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视图方法。

有什么建议吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-09 04:17:53

继承TabChatViewModelScreen类(由框架提供)定义了TryClose方法。此方法尝试通过询问其父屏幕(在本例中为ChatShellViewModel conductor)或要求关闭视图来关闭当前屏幕。

因此,您所需要做的就是在调用close操作时从TabChatViewModel中调用TryClose()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4924582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档