2013-08-21 40 views
5

WPF projesinde MVVM ile AvalonDock kullanıyorum.WPF - AvalonDock - Kapanış Belgesi

"X" 'ye ("Sekme Kapat") bastığımda, belgem kapanıyor, ancak bellekte kalıyor. Görünüşe göre sadece gizli. Model.Documents koleksiyonumdan kaldırılmadı.

DockingManager_DocumentClosing ekler ve belgesini koleksiyondan kaldırmaya çalışırsanız, aşağıdaki yöntemde bir Özel Durum alırsınız, çünkü parentAsContainer boştur.

/// <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(); 
} 

herkes ben onun Close düğmesine vurduğunda sonunda bertaraf edilmesi edilebilmesi için benim Model.Documents çıkarılabilir AvalonDock belgeyi yönetmek nasıl biliyor mu? Başvuru için

:

<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> 

cevap

2

Aslında kabul edilemez bir geçici çözüm bulmak: Bu AvalonDock benim XAML olduğunu. Gerçekten bükülmüş.

Sadece bunu referans olarak verdim. Bunu yapmanın temiz bir yolu olmalı.

// ************************************************************************ 
    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); 
     } 
    } 
+0

MVVM'yi kullanmıyorsanız bunu düzeltmenin bir yolu var mı? –

+0

Bilmiyorum ??? (Gecikme için özür dilerim ... Sadece soruyu gördüm) –

+0

Bu uzun bir atış, ama bu olay bana hiç çağrılmadı, başka birinin benzer bir deneyimi var mı? –

-1

IsVisibleChanged için kayıt. CanClose="False" veya CanFloat="False":

void layoutFPR_Hidden(object sender, EventArgs e) 
{ 
    LayoutAnchorable window = (LayoutAnchorable)sender; 
    YourClass content = window.Content as YourClass; 

    // Close the object 
    content = null; 
    ((LayoutAnchorable)sender).Close(); 

} 
0

Ben LayoutDocument veya LayoutAnchorablePane, bu ayarı hem uygulayarak çalışır bulduk.

Kapat düğmesini kaldırır.

<avalonDock:LayoutDocument Title="Board" 
          ContentId="Board" 
          CanClose="False" 
          CanFloat="False"> 
</avalonDock:LayoutDocument>