当我点击“X”(选项卡的关闭按钮)时,我的文档关闭但保留在内存中.它似乎只是隐藏的.它不会从我的Model.documents集合中删除.
如果我添加DockingManager_documentClosing并尝试从集合中删除我的文档,我会在Xceed.Wpf.AvalonDock.Layout.LayoutContent的以下方法中收到一个Exception,因为parentAsContainer为null.
/// <summary>/// Close the content/// </summary>/// <remarks>Please note that usually the anchorable is only hIDden (not closed). By default when user click the X button it only hIDes the content.</remarks>public voID Close(){ var root = Root; var parentAsContainer = Parent as ILayoutContainer; parentAsContainer.RemoveChild(this); if (root != null) root.CollectGarbage(); OnClosed();}
有没有人知道我如何管理AvalonDock中可以从我的Model.documents中删除的文件,以便在我点击其关闭按钮时最终被处理掉?
供参考:这是我的AvalonDock的XAML:
<avalonDock:DockingManager x:name="DockingManager" documentsSource="{Binding documentItems}" ActiveContent="{Binding ActiveMainWindowviewmodel,Converter={StaticResource RestrictedClassConverter},ConverterParameter={x:Type multisimAnalysis:MainWindowviewmodel},Mode=TwoWay}" documentClosing="DockingManager_documentClosing" ActiveContentChanged="DockingManager_ActiveContentChanged"> <avalonDock:DockingManager.LayoutItemContainerStyleSelector> <pane:PanesStyleSelector> <pane:PanesStyleSelector.MainWindowVIEwLcStyle> <Style targettype="{x:Type avalonDock:LayoutItem}"> <Setter Property="Title" Value="{Binding Model.Title}"/> <Setter Property="tooltip" Value="{Binding Model.Title}"/> <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/> <Setter Property="IconSource" Value="{Binding Model.IconSource}"/> <Setter Property="IsSelected" Value="{Binding Model.IsSelected,Mode=TwoWay}"/> <Setter Property="IsActive" Value="{Binding Model.IsActive,Mode=TwoWay}"/> <Setter Property="ContentID" Value="{Binding Model.ContentID}"/> </Style> </pane:PanesStyleSelector.MainWindowVIEwLcStyle> </pane:PanesStyleSelector> </avalonDock:DockingManager.LayoutItemContainerStyleSelector> <avalonDock:DockingManager.LayoutItemTemplateSelector> <multisimAnalysis:PanestemplateSelector> <multisimAnalysis:PanestemplateSelector.MainWindowLcTemplate> <DataTemplate> <multisimAnalysis:MainWindowVIEwLc /> </DataTemplate> </multisimAnalysis:PanestemplateSelector.MainWindowLcTemplate> </multisimAnalysis:PanestemplateSelector> </avalonDock:DockingManager.LayoutItemTemplateSelector> <avalonDock:DockingManager.theme> <avalonDock:VS2010theme/> </avalonDock:DockingManager.theme> <avalonDock:LayoutRoot> <avalonDock:LayoutPanel OrIEntation="Horizontal"> <avalonDock:LayoutAnchorablePane DockWIDth="400"> <avalonDock:LayoutAnchorable title="Scope(s) selection" x:name="PanelScopeSelection" IsVisible="True"> <scopeSelection:UserControlSelectStudyScope x:name="ToolScopeSelection"/> </avalonDock:LayoutAnchorable> </avalonDock:LayoutAnchorablePane> <avalonDock:LayoutdocumentPane/> <avalonDock:LayoutAnchorablePane DockWIDth="150"> <avalonDock:LayoutAnchorable title="PropertIEs" x:name="PanelScopePropertyGrID"> <!--<multisimAnalysis:UserControlPropertyGrID x:name="ToolPropertyGrID" />--> <xctk:PropertyGrID x:name="ToolPropertyGrID" Selectedobject="{Binding ActiveObject}" /> </avalonDock:LayoutAnchorable> </avalonDock:LayoutAnchorablePane> </avalonDock:LayoutPanel> </avalonDock:LayoutRoot></avalonDock:DockingManager>解决方法 我实际上找到了一个不可接受的解决方法.
真是扭曲了.
我只是作为参考.应该有一个干净的方法来做到这一点.
// ************************************************************************ private voID DockingManager_documentClosing(object sender,Xceed.Wpf.AvalonDock.documentClosingEventArgs e) { e.document.CanClose = false; documentModel documentModel = e.document.Content as documentModel; if (documentModel != null) { dispatcher.BeginInvoke(new Action(() => this.Model.documentItems.Remove(documentModel)),dispatcherPriority.Background); } }总结
以上是内存溢出为你收集整理的c# – WPF – AvalonDock – 结账凭证全部内容,希望文章能够帮你解决c# – WPF – AvalonDock – 结账凭证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)