RegionAdapter for Prism

Jul 6, 2010 at 5:12 PM

If nobody did it yet, I wrote two articles on how to use the awesome Avalon Dock with Prism.

Guy you control it's awesome and free! You screwed-up Telerik and ActiPro, great job!!

Part 01

Part 02

This week-end I will create the Full region adapter for avalon, then I will submit the code here.

 

Jul 6, 2010 at 8:35 PM

I have exactly the same requirement, and for now I solved it using the messaging system. In the module that has to be added as a document pane, there is one line of code:

_messagingService.Publish.OpenDocumentRequest(new DocumentProperties() { AllowOnlyOneInstance = true, HeaderName = "AdminModule", View = _adminView });

In the shell, the request is handled in order to show the view as a document:

_messagingService.SubscribeTo.OpenDocumentRequest(m =>
                {
                    ManagedContent document = null;
                    if (m.AllowOnlyOneInstance)
                        document = dockingManager.Documents.Where(d => d.Name == m.HeaderName).SingleOrDefault();
                    if (document == null)
                    {
                        var dc = new DocumentContent() {Title = m.HeaderName, Name = m.HeaderName};                       

                        // Dynamically bind Title to Title
                        BindingOperations.SetBinding(dc, DocumentContent.TitleProperty, new Binding("Title"));        
                        dc.DataContext = m.View.DataContext;
                        dc.Content = m.View;
                        dc.Show(dockingManager);
                        dc.Focus();
                    }
                });

It's possible to specify if only want one instance is allowed, as well as the tab header which is databound to the Title property of the view model.

Your approach probably is a better one, I don't know prism that well. So I'm looking forward to your code, to see if I can maybe replace mine :) Would it be possible in your code to specify that a specific module can only have one instance as a document?

Jul 6, 2010 at 9:37 PM

What I did in my region adapter for Avalon (W.I.P.) it's:

  1. a behavior for the events of the docks using the weakevents, so if you add a view or close a view or add a pane or close a pane everything is orchestrated
  2. the shell doesn't know anymore avalon ...
  3. the module can have a view of any type, like a usercontrol, and you don't care because the region adapter will transform it in a pane

It should be ready in 1 week.

:-)

 

PS: The message system you use it's dangerous if you open a lot of views as it keeps the memory high, did you notice?

Jul 7, 2010 at 8:47 AM
raffaeu wrote:

What I did in my region adapter for Avalon (W.I.P.) it's:

  1. a behavior for the events of the docks using the weakevents, so if you add a view or close a view or add a pane or close a pane everything is orchestrated
  2. the shell doesn't know anymore avalon ...
  3. the module can have a view of any type, like a usercontrol, and you don't care because the region adapter will transform it in a pane

It should be ready in 1 week.

:-)

 

PS: The message system you use it's dangerous if you open a lot of views as it keeps the memory high, did you notice?

Meanwhile I discovered the video http://development-guides.silverbaylabs.org/Video/Prism-Regions#videolocation_6 in which they explain how to create a region adapter, so it's starting to make more sense now. I'm still very interested to see a demo of how you implemented it. For example, if the shell doesn't know about Avalon, where do you define the docking manager? And indeed, the views should be usercontrols, which they are also in my solution. I'm not sure about the memory problem... haven't checked that. I'm not using KeepSubscriberReferenceAlive anywhere...

Anyway, if you have a demo app, let us know, looking forward to it! :)

Nov 15, 2010 at 8:58 PM

did the final version of the adapter ever get published for download...if so...can someone send me a link.

Thanks in advance.

Paul

Mar 29, 2011 at 7:51 AM

Hey

I was going through this thread and am intrested to know if the region adapter is available for download.

Thanks

Vikas

Apr 20, 2011 at 8:24 PM

Hi raffaeu , I too am interested in seeing this source ? I couldn't find a reference to it on your blog or in avalondock.codeplex.com . Did this end up working because I am on the same path and I am following some of your advice in the blog posting. If there was some limitation that prevented completion let me know please. 

 

Thanks

Apr 21, 2011 at 10:59 PM

never mind I just tried it out and realized that that was all the code required in the blog posting. 

May 4, 2011 at 1:17 PM

Another way is to embed AvalonDock in a UserControl and load it using the region manager features.

Then add methods to this UserControl so that it creates DocumentContent and DockableContent with content inside.

This what does the SofaContainer control.

Of course this is more a workaround allowing to get AvalonDock features (resizing, drag, floating windows etc...) in a Prism application than a true answer to the region adapter creation ...

Bernard from Sofa, an AvalonDock wrapper.