|By Bruce Armstrong||
|August 16, 2011 10:02 AM EDT||
In a previous PBDJ article, we looked at using a third-party control, a ribbon control in particular, in a PowerBuilder WPF target. One of the other "most requested" features people have asked for is the capability to provide docking windows in their PowerBuilder applications. In this article, we're going to look at how we can do that in a PowerBuilder WPF application using a third-party docking manager.
The particular docking manager I'm going to use is the AvalonDock, an open source project on CodePlex (http://avalondock.codeplex.com/). At the time of this writing, the current version is 1.3.3571. However, that one has some dependencies on Visual Studio 2010 and .NET Framework 4.0 libraries. PowerBuilder .NET 12 is based on the Visual Studio 2008 isolated shell, so I'm using an older build (1.1.1509) that doesn't have these dependencies.
First, we'll add the AvalonDock assembly and a reference to a new WPF application. Create a new WPF window and add the AvalonDock namespace to the Usings property for the new window. I called that new window w_frame, and coded the open event of the application object to open it. I then dropped a DockingManager control onto the window. Next create a menu (I called mine m_menu) and associate that menu with the new window as well.
I then edited the XAML for the new window to provide a couple of RowDefinitions and to add a StatusBar to the bottom of the window. My modified window XAML looks like this:
<my:DockingManager x:Name="dockingmanager1" Grid.Row="0">
<StatusBarItem Content="Docking Panel Demo"/>
The bottom RowDefinition is 24 units high, and the top RowDefinition takes up whatever remaining space there is (the majority of the window). The DockingManager is located in the top RowDefintion (Rows is a zero-based collection), and the StatusBar is assigned to the bottom RowDefinition.
I'm also going to create three instance variables in the window for the ResizingPanel, a DocumentPanel, and a DockablePanel:
In the open event of the window I'll instantiate those items, associate the DockablePane and the DocumentPane to the ResizingPanel, and finally associate the ResizingPanel to the DockManager we added in the designer:
resPanel = create ResizingPanel
resPanel.Orientation = System.Windows.Controls.Orientation.Horizontal!
dockPane = create DockablePane
documentPane = create DocumentPane
dockingmanager1.Content = resPanel
In the menu, I'll add two menu items: one to open a document "sheet" into the DocumentPane and another to open a "tab" in the DockablePane. They'll just fire events on the window that will actually do the work though. For example:
ParentWindow.event dynamic ue_opensheet()
Here's where it gets interesting. What the docking manager wants to see opening into the DockablePane and the DocumentPane are objects derived from the DockableContent and DocumentContent classes. What we're going to do is create a couple of PowerBuilder custom visual user objects, and then create an inner control on each of those classes. In an existing application, you would need to modify the XAML for your window ancestor classes to accomplish the same thing. The XAML for the resulting objects, u_document and u_panel, look like this Listings 1 and 2. (Listings 1-3 can be downloaded here.)
Now we can go back to w_frame and code the events that open a "sheet" (u_document) and a "tab" (u_panel) (see Listing 3).
Run the app, select the options to open a sheet and a panel two times each, and you should have something that looks similar to Figure 1. Some things to note:
- Dockable items are capable of autohiding.
- Dockable items can also be "floated" and moved outside of the frame, even onto a second monitor, giving multi-monitor support.
- If an item is given a name, the DockingManager can serialize the layout of those items and store it so that it can be reloaded the next time the application runs. The result is that the user's preference for the pane layouts can be remembered between sessions.
- At any time you can drag an item and use the layout indicators to create new docking groups or move the item onto an existing docking group (see Figure 2).
There you have it - multiple-monitor support, docking panes, autohiding panes and the ability to store and retrieve layouts. Everything you need to create state-of-the-art GUI applications.
Note: Special thanks go out to Peter Conn of the U.S. Census Bureau. His presentation of how he implemented something similar using a commercial third-party docking manager at TechWave 2010 is what prompted me to look into doing it with an open source implementation. He also helped me through some of the stumbling blocks I ran into as I was putting it together.
|russf0426 10/31/12 12:40:00 PM EDT|
Can you elaborate on your choice of avalon? Is your example not possible with the default dockpanel?
|acartagenas 08/21/11 04:45:00 AM EDT|
This is a very good article for us PB developers. However, the word doc does not exists on the web server.
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- Creation and Consumption of Web Services with PowerBuilder
- Cloud People: A Who's Who of Cloud Computing
- DDDW Tips and Tricks
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Working with SOA & Web Services in PowerBuilder
- Dynamically Creating DataWindow Objects
- Cloud Expo, Inc. Announces Cloud Expo 2011 New York Venue
- OLE - Extending the Capabilities of PowerBuilder