In This Article

Working with Documents

All documents can be easily managed via DockSite properties and methods, regardless of whether tabbed or standard MDI is in use. This allows your document-related code to remain the same regardless of the style of MDI in use.

Creating a New Document

A document is just a term referring to a docking window (either a tool or document window) that is in the MDI area.

See the Lifecycle and Docking Management topic for details on how to create a new docking window via code.

Additional Document Window Properties

Document windows have a couple additional properties that aid in their user interface presentation.

The DocumentWindow.FileName property should be set to the full file or URL path of the document content, if appropriate. If this doesn't apply, leave the value null.

The DocumentWindow.Description property should be set to a description of the document type, such as: "Text document". This value gets displayed on a standard switcher.

Opening a Document

Opening a document will make it visible in the UI, but it won't necessarily be selected or have focus. To ensure a document is opened, selected, and focused, it must be activated instead.

A call to the DockingWindow.Open method will open the document. Alternatively, the IsOpen property can be set to true.

DocumentWindow controls will always open in the MDI area. ToolWindow controls on the other hand will only open in the MDI area if their State is Document before the open occurs.

Activating a Document

Activating a document will open it, select it, and focus its content as well. There is no need to open a document before activating it, because activating includes the open behavior.

A call to the DockingWindow.Activate method will activate the document. An overload of this method allows you to ensure the document is selected but not focused. Alternatively, the IsActive property can be set to true.

As described above, to ensure that a ToolWindow opens in the MDI area, make sure its State property is set to Document before activating it.

Enumerating Open Documents

Use the DockSite.Documents collection to enumerate through the open documents.

Sort the collection by DockingWindow.LastActiveDateTime to order them by which the documents were last activated.

The DockSite.HasDocuments property indicates whether there are currently any open documents.

Primary Document

The DockSite.PrimaryDocument property gets the document that currently is the primary document in the dock site. The primary document is the same as DockSite.ActiveWindow if the active window is a document. When the DockSite.ActiveWindow is not a document, then the primary document is the open document that was last activated.

The DockSite.PrimaryDocumentChanged event is raised whenever the primary document changes.

Working with Open Documents

There are numerous DockSite methods that can be used to manipulate open documents.

Member Description
ActivateNextDocument Method Activates the next document.
ActivatePreviousDocument Method Activates the previous document.
ActivatePrimaryDocument Method Activates the primary (currently selected) document DockingWindow, if there is one.
CascadeDocuments Method Cascades all open documents, if using tabbed or standard MDI.
CloseAllDocuments Method Closes all open documents.
ClosePrimaryDocument Method Closes the primary (currently selected) document DockingWindow if there is one.
TileDocumentsHorizontally Method Tiles all open documents horizontally, if using tabbed or standard MDI.
TileDocumentsVertically Method Tiles all open documents vertically, if using tabbed or standard MDI.

Closing a Document

A document can be closed by calling its DockingWindow.Close method.

Warning

For document windows this will also destroy the window by default unless the DockSite.AreDocumentWindowsDestroyedOnClose property is set to false.

Contextual Content

Tabbed MDI tabs and standard MDI window title bars can display custom contextual content such as buttons or status indicators.

See the Contextual Content topic for some more information.

Read-Only Documents

Document windows have a special feature for automatically supporting the representation of read-only states. When a document window should be marked as read-only in the user interface, set DocumentWindow.IsReadOnly property to true. This will display a small lock context icon next to the document title.