We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DockingManager MVVM using Unity to resolve views

I was able to use your MVVM docking demo to get my application working, but, I would like to use Unity to resolve the view to the supplied view model instead of defining data templates.  I have defined 4 permanent docking regions and i am trying to add new tabbed documents as per the example you provide.  Here is the code that I am trying to use:

                            FrameworkElement view= viewLocator(viewModel); // Unity is used to resolve the view from the vm based on convention.
                            DockingManager.SetHeader(view, ((IDockElement)viewModel).Header);
                            DockingManager.SetState(view, DockState.Document);
                            dockingManager.Children.Add(view); // exception thrown here.

I get the following message thrown in mscorlib:

The Value "MyProduct.MyApp.Views.MyView" is not of type "System.Object" and cannot be used in this generic container.

The view is indeed a UserControl which does derive from System.Object.  I don't understand how adding my Unity resolved control to the collection is different than adding a contentcontrol but evidently it is.  Can someone please provide some insight?  I see the wisdom in using the viewmodel to drive the GUI but, I would like to use Unity to resolve my views.

thanks in advance

7 Replies

VR Vijayalakshmi Roopkumar Syncfusion Team March 16, 2016 12:23 PM UTC

Hi Scot,

Thank you for using Syncfusion products,

Our DockingManager will accept the Framework element as a child and there is no exception occuring when adding the framework element as children as per your code snippet. So, please provide us your sample with your usercontrol view[MyProduct.MyApp.Views.MyView] as this would be helpful for us to analyse and sort out your exact problem and provide you the solution accordingly.

Regards,
Vijayalakshmi V.R.


SB Scot Braze March 16, 2016 02:51 PM UTC

Thanks much for your prompt reply. I am attaching a zip file that should compile and run.  This was built against the 4.5 runtime using your libraries and prism 5 with Unity.  No other external dependencies should be needed.

Lines 253 and 254 in DockingAdapter.xaml.cs is where you can comment / uncomment code to force it to use a VM with a template or the viewLocator.  It works properly with the VM being assigned to the content of a content control, but the locator gives the error (trapped on line 261) originally mentioned in my post.  I tried assigning the resolved control to the content of the content control, but that results in the same error.

The 4 docked windows will have their Views resolved via Prism Region View Injection at runtime.  I have omitted this code as it really doesn't have anything to do with the issue i am trying to resolve.

thanks again,

scot.

Attachment: SyncfusionDockingDemo_9e5efaa1.zip


MS Marimuthu Sivalingam Syncfusion Team March 17, 2016 01:48 PM UTC

Hi Scot,

Thank you for your update.

We have try to run your sample, but we are not able to build the sample. While we check the sample, we found that PRISM assembly get conflict with the assembly version. We are trying to download the particular PRISM version assemblies. Meanwhile if you have the assemblies please update us, it would help to provide solution at the earliest.

Regards,
Marimuthu S.


SB Scot Braze March 17, 2016 01:58 PM UTC

Sorry about that, I figured nuget would resolve things properly.  I was trying to save a little bandwidth :).  I have attached a new zip file with the packages directory included.  This should give you the references you need.

thanks again.

Attachment: SyncfusionDockingDemo_824a1a96.zip


VR Vijayalakshmi Roopkumar Syncfusion Team March 18, 2016 09:09 AM UTC

Hi Scot,

Thank you for providing the packages,

In our DockingMVVM sample, we are maintaining the ActiveDocument as IDockElement. Invalid cast exception occurs because of casting the content of the ContentControl to IDockElement for assigning it to the ActiveDocument in dockingManager_ActiveWindowChanged event. Now we have resolved the exception by checking whether the content is IDockElement type before assigning it to ActiveDocument. Please download the modified sample from the following location:

Sample:SyncfusionDockingDemo_Modified

Regards,
Vijayalakshmi V.R.


SB Scot Braze March 24, 2016 02:37 PM UTC

What a silly error on my part.  Thanks much for the assist.  I am evaluating your controls for use when it comes time for me to move from winforms to WPF and i must say that the support so far has been wonderful.  I am on to another issue, but it has nothing to do with this.  I will create a new thread with sample code. 

thanks again for the excellent support.

scot.


VR Vijayalakshmi Roopkumar Syncfusion Team March 25, 2016 06:48 AM UTC

Hi Scot,

Thank you for your update,

Please let us know if you need further assistance on this

Regards,
Vijayalakshmi V.R.

Loader.
Up arrow icon