2011-09-20 41 views
1

我已經看到了一些像this one這樣的問題,但是我想要使用的對接庫必須有一個重要的特性,它沒有被問到:它必須支持MVVM。支持MVVM的WPF對接庫

因此,在Telerik,DotNetBar,DevZest和其他庫周圍的其他庫(不包括我已經測試過的AvalonDock)中,有沒有實際與MVVM一起使用的庫?

在此先感謝

+0

AvalonDock應該工作,我知道人們用它與Caliburn Micro。 http://goo.gl/gRVo5 –

+0

@Derek Beattie:不,AvalonDock不是MVVM兼容的。我遇到了很多麻煩,不得不擴展組件。我會盡快寫一篇關於它的博客文章,以便讓任何有需要的開發人員可以使用 – Damascus

+0

是的,我很好奇它是什麼使它不兼容Mvvm,我從未使用它。 –

回答

2

您好邁克嘗試這樣的:

  1. 簡單的方法:實施Sofa, An adaptation of AvalonDock for Prism
  2. 使用AvalonDock和實現自定義區域適配器是這樣的:

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

和你在你的XAML中可以這樣實現它:

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

它是如何工作的? 簡單,首先在所有你必須記住,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.

而一個DockingManager is the core control in AvalonDock. It arranges contained panes, handles fly out panes and floating windows.

所以,下面這個例子中,你可能已經實現Avalon的自定義區域適配器,我在一個項目中此實現獲取工作令人敬畏的結果。

關注

+0

感謝您的回答。不幸的是,我使用CaliburnMicro而不是Prism。我會看看沙發,看看我能不能找到解決辦法 – Mike