一个支持MVVM的WPF对接库

发布于 2024-12-06 02:25:26 字数 264 浏览 0 评论 0原文

我已经看到过一些问题,例如这个,但是对接库我想使用必须有一个重要的功能,这是没有被要求的:它必须支持MVVM。

那么,在 Telerik、DotNetBar、DevZest 和其他库(不包括我已经测试过的 AvalonDock)中,有没有一个是您实际与 MVVM 一起使用的?

提前致谢

I've already seen some questions like this one, but the docking library I'd like to use must have an important feature, which was not asked: it must support MVVM.

So, among Telerik, DotNetBar, DevZest, and the other libraries around there (excluding AvalonDock, which I have already tested), is there one you actually use with MVVM?

Thanks in advance

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

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

发布评论

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

评论(1

遥远的绿洲 2024-12-13 02:25:26

你好,迈克尝试一下:

  1. 简单的方法:实现 Sofa,AvalonDock for Prism 的改编版
  2. 使用 AvalonDock 和像这样实现自定义区域适配器:

    public class ResizingPanelRegionAdapter : RegionAdapterBase;
    {
    公共ResizingPanelRegionAdapter(IRegionBehaviorFactory工厂)
        :基地(工厂)
    {
    
    }
    受保护覆盖​​ IRegion CreateRegion()
    {
        返回新的AllActiveRegion();
    }
    
    protected override void Adapt(IRegion 区域, DockingManager RegionTarget)
    {
        Region.Views.CollectionChanged += delegate(对象发送者, NotifyCollectionChangedEventArgs e)
        {
            OnViewsCollectionChanged(发送者,e,区域,regionTarget);
        };
    }
    
    私有无效OnViewsCollectionChanged(对象发送者,NotifyCollectionChangedEventArgs e,IRegion区域,DockingManagerregionTarget)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            foreach(e.NewItems 中的对象项)
            {
                UIElement 视图 = 项目作为 UIElement;
                如果(视图!= null)
                {
                    //得到 
                    ResizingPanel resizingPanel = GetResizingPanel(regionTarget.Content);
                    resizingPanel.Background = Brushes.White;
                    DocumentPane 文档 = GetDocumentPane(resizingPanel.Children);
                    //document.Background = Brushes.White;
    
                    DocumentContent newContentPane = new DocumentContent();
                    newContentPane.Content = 项目;
                    var itemView = (item as IViewBase);
                    if (itemView != null)
                        newContentPane.Title = itemView.Title;
                    //当contentPane关闭时删除关联的区域
                    newContentPane.Closed += (contentPaneSender, args) =>
                    {
                        区域.删除(项目);
                        newContentPane.Content = null;
                    };
    
                    document.Items.Add(newContentPane);
    
                    if (!resizingPanel.Children.Contains(文档))
                        resizingPanel.Children.Add(文档);
    
                    RegionTarget.Content = resizingPanel;
    
                    newContentPane.Activate();
                    区域.激活(项目);
                }
            }
        }
        else if (e.Action == NotifyCollectionChangedAction.Remove)
        {
    
        }
    }
    
    私有 DocumentPane GetDocumentPane(UIElementCollection 集合)
    {
        foreach(集合中的对象项)
        {
            var documentPanel = item 作为 DocumentPane;
            if (文档面板!= null)
                返回文档面板;
        }
        返回新的 DocumentPane();
    }
    
    private ResizingPanel GetResizingPanel(对象内容)
    {
        var resizingPanel = 内容为 ResizingPanel;
        if (调整大小面板!= null)
            返回调整大小面板;
        返回新的 ResizingPanel();
    }    
    }
    

在 XAML 中,您可以如下实现它:

<avalon:DockingManager prism:RegionManager.RegionName="MainRegion">
</avalon:DockingManager>

它是如何工作的?
简单,首先您必须记住 区域适配器负责创建区域并将其与控件关联。这允许您使用 IRegion 接口以一致的方式管理 UI 控件内容。

以及一个 DockingManager 是 AvalonDock 中的核心控件。它排列包含的窗格、处理飞出窗格和浮动窗口。

因此,按照此示例,您可以为 Avalon 实现自定义区域适配器,我在一个项目中使用此实现,获得了很棒的结果。

问候

Hello Mike try with this:

  1. Easy way: Implement Sofa, An adaptation of AvalonDock for Prism
  2. Using AvalonDock and implementing a custom region adapter like this:

    public class ResizingPanelRegionAdapter : RegionAdapterBase<DockingManager>
    {
    public ResizingPanelRegionAdapter(IRegionBehaviorFactory factory)
        : base(factory)
    {
    
    }
    protected override IRegion CreateRegion()
    {
        return new AllActiveRegion();
    }
    
    protected override void Adapt(IRegion region, DockingManager regionTarget)
    {
        region.Views.CollectionChanged += delegate(Object sender, NotifyCollectionChangedEventArgs e)
        {
            OnViewsCollectionChanged(sender, e, region, regionTarget);
        };
    }
    
    private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            foreach (object item in e.NewItems)
            {
                UIElement view = item as UIElement;
                if (view != null)
                {
                    //Get 
                    ResizingPanel resizingPanel = GetResizingPanel(regionTarget.Content);
                    resizingPanel.Background = Brushes.White;
                    DocumentPane document = GetDocumentPane(resizingPanel.Children);
                    //document.Background = Brushes.White;
    
                    DocumentContent newContentPane = new DocumentContent();
                    newContentPane.Content = item;
                    var itemView = (item as IViewBase);
                    if (itemView != null)
                        newContentPane.Title = itemView.Title;
                    //When contentPane is closed remove the associated region
                    newContentPane.Closed += (contentPaneSender, args) =>
                    {
                        region.Remove(item);
                        newContentPane.Content = null;
                    };
    
                    document.Items.Add(newContentPane);
    
                    if (!resizingPanel.Children.Contains(document))
                        resizingPanel.Children.Add(document);
    
                    regionTarget.Content = resizingPanel;
    
                    newContentPane.Activate();
                    region.Activate(item);
                }
            }
        }
        else if (e.Action == NotifyCollectionChangedAction.Remove)
        {
    
        }
    }
    
    private DocumentPane GetDocumentPane(UIElementCollection collection)
    {
        foreach (object item in collection)
        {
            var documentPanel = item as DocumentPane;
            if (documentPanel != null)
                return documentPanel;
        }
        return new DocumentPane();
    }
    
    private ResizingPanel GetResizingPanel(object content)
    {
        var resizingPanel = content as ResizingPanel;
        if (resizingPanel != null)
            return resizingPanel;
        return new ResizingPanel();
    }    
    }
    

And your in your XAML you could implement it like this:

<avalon:DockingManager prism:RegionManager.RegionName="MainRegion">
</avalon:DockingManager>

How it works?
Simple, first at all you have to keep in mind that Region adapters are responsible for creating a region and associating it with the control. This allows you to use the IRegion interface to manage the UI control contents in a consistent way.

And a DockingManager is the core control in AvalonDock. It arranges contained panes, handles fly out panes and floating windows.

So, following this example you could have implemented a custom region adapter for avalon, I worked with this implementation in a project getting awesome results.

Regards

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