c# – 带有棱镜区域适配器的AvalonDock

c# – 带有棱镜区域适配器的AvalonDock,第1张

概述我已经看到了一些关于SO的问题,但它们似乎都不适用于我.我希望能够使用带有Prism 4的伟大的 Avalondock 2.0.但是,所有的样本区域适配器都是针对Avalondock 1.x系列,我无法让它工作. 有没有人有关于如何为AvalonDock的LayoutDocumentPane和LayoutAnchorablePane创建Region Adapter的示例代码? 不幸的是,据我所知, 我已经看到了一些关于SO的问题,但它们似乎都不适用于我.我希望能够使用带有Prism 4的伟大的 Avalondock 2.0.但是,所有的样本区域适配器都是针对Avalondock 1.x系列,我无法让它工作.

有没有人有关于如何为AvalonDock的LayoutdocumentPane和LayoutAnchorablePane创建Region Adapter的示例代码?

解决方法 不幸的是,据我所知,“LayoutdocumentPane”和“LayoutAnchorablePane”都不允许包含/创建regionadapters,但是“DockingManager”会这样做.一种解决方案是为DockingManager创建regionadapter,然后管理可视树中“Layoutdocuments”的实例化.

xaml看起来如下:

<ad:DockingManager Background="AliceBlue" x:name="WorkspaceRegion" prism:RegionManager.Regionname="WorkspaceRegion">                        <ad:LayoutRoot>                            <ad:LayoutPanel>                                <ad:LayoutdocumentPaneGroup>                                    <ad:LayoutdocumentPane>                                    </ad:LayoutdocumentPane>                                </ad:LayoutdocumentPaneGroup>                            </ad:LayoutPanel>                        </ad:LayoutRoot>                    </ad:DockingManager>

请注意,该区域在DockingManager标记中定义,并且LayoutPanel下存在一个LayoutdocumentPaneGroup. LayoutdocumentPaneGroup下的LayoutdocumentPane将托管与要添加到“WorkspaceRegion”的视图关联的Layoutdocuments.

至于regionadapter本身,请参考下面的代码,我提供了解释性注释

#region Constructor        public AvalonDockregionadapter(IRegionBehaviorFactory factory)            : base(factory)        {        }        #endregion  //Constructor        #region OverrIDes        protected overrIDe IRegion CreateRegion()        {            return new AllActiveRegion();        }        protected overrIDe voID Adapt(IRegion region,DockingManager regionTarget)        {            region.VIEws.CollectionChanged += delegate(                Object sender,NotifyCollectionChangedEventArgs e)                {                    this.OnVIEwsCollectionChanged(sender,e,region,regionTarget);                };            regionTarget.documentClosed += delegate(                            Object sender,documentClosedEventArgs e)            {                this.OndocumentClosedEventArgs(sender,region);            };        }        #endregion  //OverrIDes        #region Event Handlers        /// <summary>        /// Handles the NotifyCollectionChangedEventArgs event.        /// </summary>        /// <param name="sender">The sender.</param>        /// <param name="e">The event.</param>        /// <param name="region">The region.</param>        /// <param name="regionTarget">The region target.</param>        voID OnVIEwsCollectionChanged(object sender,NotifyCollectionChangedEventArgs e,IRegion region,DockingManager regionTarget)        {            if (e.Action == NotifyCollectionChangedAction.Add)            {                foreach (FrameworkElement item in e.NewItems)                {                    UIElement vIEw = item as UIElement;                    if (vIEw != null)                    {                        //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)                        Layoutdocument newLayoutdocument = new Layoutdocument();                        //Set the content of the Layoutdocument                        newLayoutdocument.Content = item;                        viewmodelBase_2 viewmodel = (viewmodelBase_2)item.DataContext;                        if (viewmodel != null)                        {                            //All my viewmodels have propertIEs displayname and IconKey                            newLayoutdocument.Title = viewmodel.displayname;                            //GetimageUri is custom made method which gets the icon for the Layoutdocument                            newLayoutdocument.IconSource = this.GetimageUri(viewmodel.IconKey);                        }                        //Store all Layoutdocuments already pertaining to the LayoutdocumentPane (defined in xaml)                        List<Layoutdocument> oldLayoutdocuments = new List<Layoutdocument>();                        //Get the current ILayoutdocumentPane ... Depending on the arrangement of the vIEws this can be either                         //a simple LayoutdocumentPane or a LayoutdocumentPaneGroup                        ILayoutdocumentPane currentILayoutdocumentPane = (ILayoutdocumentPane)regionTarget.Layout.RootPanel.Children[0];                        if (currentILayoutdocumentPane.GetType() == typeof(LayoutdocumentPaneGroup))                        {                            //If the current ILayoutdocumentPane turns out to be a group                            //Get the children (Layoutdocuments) of the first pane                            LayoutdocumentPane oldLayoutdocumentPane = (LayoutdocumentPane)currentILayoutdocumentPane.Children.ToList()[0];                            foreach (Layoutdocument child in oldLayoutdocumentPane.Children)                            {                                oldLayoutdocuments.Insert(0,child);                            }                        }                        else if (currentILayoutdocumentPane.GetType() == typeof(LayoutdocumentPane))                        {                            //If the current ILayoutdocumentPane turns out to be a simple pane                            //Get the children (Layoutdocuments) of the single existing pane.                            foreach (Layoutdocument child in currentILayoutdocumentPane.Children)                            {                                oldLayoutdocuments.Insert(0,child);                            }                        }                        //Create a new LayoutdocumentPane and inserts your new Layoutdocument                        LayoutdocumentPane newLayoutdocumentPane = new LayoutdocumentPane();                        newLayoutdocumentPane.InsertChildAt(0,newLayoutdocument);                        //Append to the new LayoutdocumentPane the old Layoutdocuments                        foreach (Layoutdocument doc in oldLayoutdocuments)                        {                            newLayoutdocumentPane.InsertChildAt(0,doc);                        }                        //Traverse the visual tree of the xaml and replace the LayoutdocumentPane (or LayoutdocumentPaneGroup) in xaml                        //with your new LayoutdocumentPane (or LayoutdocumentPaneGroup)                        if (currentILayoutdocumentPane.GetType() == typeof(LayoutdocumentPane))                            regionTarget.Layout.RootPanel.ReplaceChildAt(0,newLayoutdocumentPane);                        else if (currentILayoutdocumentPane.GetType() == typeof(LayoutdocumentPaneGroup))                        {                            currentILayoutdocumentPane.ReplaceChild(currentILayoutdocumentPane.Children.ToList()[0],newLayoutdocumentPane);                            regionTarget.Layout.RootPanel.ReplaceChildAt(0,currentILayoutdocumentPane);                        }                        newLayoutdocument.IsActive = true;                    }                }            }        }        /// <summary>        /// Handles the documentClosedEventArgs event raised by the DockingNanager when        /// one of the LayoutContent it hosts is closed.        /// </summary>        /// <param name="sender">The sender</param>        /// <param name="e">The event.</param>        /// <param name="region">The region.</param>        voID OndocumentClosedEventArgs(object sender,documentClosedEventArgs e,IRegion region)        {            region.Remove(e.document.Content);        }        #endregion  //Event handlers

不要忘记在bootstrapper中添加以下代码,以便Prism知道regionadapter的存在

protected overrIDe regionadapterMapPings ConfigureregionadapterMapPings()        {            // Call base method            var mapPings = base.ConfigureregionadapterMapPings();            if (mapPings == null) return null;            // Add custom mapPings            mapPings.RegisterMapPing(typeof(DockingManager),ServiceLocator.Current.GetInstance<AvalonDockregionadapter>());            // Set return value            return mapPings;        }

瞧.我知道这不是最干净的解决方案,但应该有效.同样的方法可以很容易地应用于“LayoutAnchorablePane”.

健康长寿·繁荣昌盛!

总结

以上是内存溢出为你收集整理的c# – 带有棱镜区域适配器的AvalonDock全部内容,希望文章能够帮你解决c# – 带有棱镜区域适配器的AvalonDock所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1262908.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存