Button in a UserControl in a Document to open another

Docking/MDI for WPF Forum

Posted 8 years ago by Dave Keller
Version: 11.1.0543
Avatar
Hi There

I am MAIN DOCUMENT with the docking controls, and then I am loading several User Controls into Document Tabs during run time. I create and load this user control (Lets call it Customers) from a Ribbon in a Tabbed MDI Docking Control. This is not a problem at all and it works fine. Take not this control(customers) was designed as a USERCONTROL and not included in the Tabbed MDI at design time.

Now, on this CUSTOMER Tab in my MDI, I placed a botton, that when clicked, it should open another usercontrol (Lets call it ORDERS) in a seperate Document Tab programatically.

I obviously cant reference my main document's code from the usercontrol at design time and as result I can't write code to load another form (Usercontrol) from there. I do not want to design ALL the documents and have them on the MDI Tab from the beginning.

Can anyone perhaps help with this.

Dave

Comments (4)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Dave,

I'm not entirely clear on your question, but from what I understand I think you have two options. The first is you can use our VisualTreeHelperExtended.GetAncestor in your UserControl to get the containing DockSite, and then open your other document.

Alternatively, you can use a RoutedCommand with your button, instead of using the Click event. Then you can add a class handler for the routed command, or possibly on the DockSite (if you don't allow floating document windows).

If you can put together a small sample project that shows what you are trying to do and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.


Actipro Software Support

Posted 8 years ago by Dave Keller
Avatar
Hi There

Thank you for the reply. Basically I have a project consisting of several UserControls and one MainWindow. This Main document will contain a MDIDockingTab and when ever you open a section, it will open a UserControl on a seperate DocumentTab.

In all your examples you open Documents from the main program Window, but I want to have a button on one of my usercontrols (opened in a document tab in the MainWindow) that when clicked - should open another usercontrol on a new DocumentTab on the MainWindow.

Have you got any samples on the VisualTreeHelperExtended.GetAncestor?

Thank you for your assistance.

Regards
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Dave,

There are several examples of using VisualTreeHelperExtended.GetAncestor in our Sample Browser. You can use Visual Studio to search all the files for "VisualTreeHelperExtended", but a simple example for your case would be:
DockSite dockSite = VisualTreeHelperExtended.GetAncestor(myUserControl, typeof(DockSite)) as DockSite;
Where myUserControl is an instance of your UserControl, which is hosted in a DockSite.


Actipro Software Support

Posted 8 years ago by Dave Keller
Avatar
Thank you so much for the example - It works exceptionally well.

But for all them VB guys ...
This is the code from a usercontrol that I used and I wanted to get the parent Docksite and aslo the MainWindow (What I called my Main MDI) ...

 Dim ds As DockSite = TryCast(VisualTreeHelperExtended.GetAncestor(Me, GetType(DockSite)), DockSite)
 
Dim r As MainWindow = TryCast(VisualTreeHelperExtended.GetAncestor(Me, GetType(MainWindow)), MainWindow)
The latest build of this product (v2019.1 build 0683) 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.