Prism、AvalonDock 区域适配器(处理关闭 DocumentPane 事件)

发布于 2024-10-16 19:07:12 字数 2079 浏览 6 评论 0原文

我有一个 Prism v4 / MEF / WPF 解决方案,可将模块视图加载到我的 Avalon Dock 中的 DocumentPane 中。我正在尝试创建关闭事件的句柄(当按下“X”来关闭 DocumentPane 时)。我无法弄清楚,这是我的 RegionAdapter 类中创建 DockableContent 的部分,也是我尝试处理关闭事件的部分(我尝试了 3 个事件):

private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DocumentPane regionTarget)
{
    if (e.Action == NotifyCollectionChangedAction.Add)
    {
        foreach (object item in e.NewItems)
        {
            UIElement view = item as UIElement;

            if (view != null)
            {
                DockableContent newContentPane = new DockableContent()
                {
                    Content = item,
                    Title = ((ITabViewInfo)view).TabViewTitle
                    Icon = ((ITabViewInfo)view).TabViewIcon
                };
                newContentPane.Closed += new EventHandler(newContentPane_Closed);
                newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
                newContentPane.Manager.DocumentClosing +=new EventHandler<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing);

                regionTarget.Items.Add(newContentPane);
                newContentPane.Activate();
            }
        }
    }
    else if (e.Action == NotifyCollectionChangedAction.Remove)
    {
        // this is never hit
        Debug.WriteLine("removed");
    }
}

这些事件永远不会被命中(我有一个 debug.writeline在每一个中):

        newContentPane.Closed += new EventHandler(newContentPane_Closed);
        newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
        newContentPane.Manager.DocumentClosing +=new EventHandler<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing);

如何处理 DocumentPane 的关闭事件?

我用于此 RegionAdapter 的代码基于 http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx

I have a Prism v4 / MEF / WPF solution that loads module views into a DocumentPane in my Avalon Dock. I'm trying to create a handle on the close event (when the 'X' is pressed to close a DocumentPane). I can't figure it out, this is the portion of my RegionAdapter class that creates the DockableContent and also where I attempt to handle the close event (I tried with 3 events):

private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DocumentPane regionTarget)
{
    if (e.Action == NotifyCollectionChangedAction.Add)
    {
        foreach (object item in e.NewItems)
        {
            UIElement view = item as UIElement;

            if (view != null)
            {
                DockableContent newContentPane = new DockableContent()
                {
                    Content = item,
                    Title = ((ITabViewInfo)view).TabViewTitle
                    Icon = ((ITabViewInfo)view).TabViewIcon
                };
                newContentPane.Closed += new EventHandler(newContentPane_Closed);
                newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
                newContentPane.Manager.DocumentClosing +=new EventHandler<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing);

                regionTarget.Items.Add(newContentPane);
                newContentPane.Activate();
            }
        }
    }
    else if (e.Action == NotifyCollectionChangedAction.Remove)
    {
        // this is never hit
        Debug.WriteLine("removed");
    }
}

These events are never hit (I have a debug.writeline in each one):

        newContentPane.Closed += new EventHandler(newContentPane_Closed);
        newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
        newContentPane.Manager.DocumentClosing +=new EventHandler<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing);

How can I handle the close event of a DocumentPane?

The code I used for this RegionAdapter is based off of http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人疚 2024-10-23 19:07:12

在这里找到答案 http://avalondock.codeplex.com/discussions/231982?ProjectName=avalondock

我必须添加:

IsCloseable = true
HideOnClose = false

Found the answer here http://avalondock.codeplex.com/discussions/231982?ProjectName=avalondock

I had to add:

IsCloseable = true
HideOnClose = false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文