How to create a "DocumentWindow"-UserControl and attach it

Docking/MDI for WPF Forum

Posted 3 years ago by Michael Bayer
Version: 16.1.0633
Avatar

Hi,

I've a view with a Ribbon-Control. Below the ribbon I've created a DockingSite. In its workspace, the application shall display DocumentWindows which contains controls like TextBoxes, ComboBoxes etc.

The ribbon contains buttons, let's say a button "Contacts" and a button "Products".

What I want to achieve is this:

If the button "Contacts" is clicked, the DocumentWindow "Contacts" with its controls should be displayed (means: added to the TabbedMDIContainer). The same with the buttton "Products".

Also: if the button "Contacts" will be clicked repeatedly, the "Contact"-DocumentWindow should be open only once or - if it is already opened but not in the foreground - should come in the front (10 clicks = 1 "Contacts"-DocumentWindow).

If the button "Products" will be clicked repeatedly, a new "Products"-DocumentWindow should be added on every click (10 clicks = 10 "Products"-DocumentWindows)

Could you please give me a helping hand how to realise that?

Thanks in advance

Michael

Comments (6)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

You could wire up commands to those two buttons.

For the Contacts command handler, you could look at DockSite.DocumentWindows to see if you already have a Contacts related DocumentWindow there.  If you find one, call Activate() on it and be done.  Otherwise, create a new one and Activate() it.

For the Products command handler, you'd just programmatically create a new DocumentWindow for each call and Activate() it.

Several of the samples show how to create documents on the fly.  For instance, search our samples project for "CreateTextDocumentWindow" and you'll see a good example.

Note that you also want to read the Docking documentation's "Lifecycle and Docking Management" topic and specifically at the "Preventing Document Windows from Auto-Destroying on Close" section.  Documents will destroy themselves on close by default, which may or may not be something you want to occur.  That flag controls that.

Hope that helps!


Actipro Software Support

Posted 3 years ago by Michael Bayer
Avatar

Hi,

thanks for this suggestion. It sounds good, but it's difficult for a newbie like me to implement, because I would need a sample. The Actipro samples are too complex and I'm missing a step by step documentation.

BTW: a viewmodel should not reference a view. Isn't it a violation, if I access the views DockSite in the viewmodel to check, whether a DocumentWindow already exists and add one, if not?

Thanks

Michael

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Sorry, you didn't mention that you were using MVVM in your original post.  In that case, the MvvmDocumentWindows QuickStart sample is a very good starting place for you.  It even implements a CreateNewTextDocumentCommand in the MainViewModel, and commands can be bound to any menu item or button in UI.  You'd want to do something similar.  In a method like our CreateNewTextDocument method that the command calls, you would look at the documentItems collection to see if a ContactViewModel is in there.  If so, you'd just call IsActive = true on it.  Otherwise you would have to make a new one and activate it.  Our MVVM features are such that you shouldn't ever need to really access UI directly from your view model.


Actipro Software Support

Posted 3 years ago by Michael Bayer
Avatar

Hi,

sorry for not mentioning, that I'm using MVVM.

Now I waded through the sample and it works as you said. Thanks a lot. But now I'm wondering how to add Tool Window to a container like a AutoHideLeftContainer. It has no ToolWindowItemSource. How can I add/bind Tool Windows to this containers in a ViewModel?

Thanks for patient helping a newbie.

Michael

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Please check out the "MVVM Features" topic in the documentation that comes with the product.  That has an "Opening and Positioning the Docking Windows" section in it.  Basically you would want to bind a VM State property to the ToolWindow State property like we do in our MvvmToolWindows sample.  Then set State = AutoHide before opening it.  I believe that also binding DefaultDockSide before opening it will let you say which auto-hide side to open on.


Actipro Software Support

Posted 3 years ago by Michael Bayer
Avatar

Thank you. That works fine.

Regards

Michael

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.