Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Collapse]Application UI Manager
   [Expand]Views
    Documents
   [Expand]Deferred Load
   [Expand]Interaction with Dock Panels
   [Expand]Bar and Ribbon Merging
   [Collapse]Examples
     How To: Create Custom Document Actions
     How to: Display Documents Using a Native MDI
     How to: Display Documents Using a Tabbed UI
     How To: Populate the Widget View in Code
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How To: Create Custom Document Actions

  1. Assume that you have a PageGroup containing 2 Documents and a Page that can display any of these Documents separately. The objective is to display different Buttons within these Containers depending on the currently activated Document. Documents are generated based on the User Controls included in the project (see the Documents topic for details). To add a Document Action to this Document, implement the ISupportDocumentActions interface for the related User Control, as demonstrated in the code below.
  2. To implement an interface's methods, use the corresponding item from the Visual Studio pop-up menu.

    The only ISupportDocumentActions interface method is ISupportDocumentActions.OnQueryDocumentActions. This method is called automatically, each time a related Document is activated. In this method, you can add custom DocumentAction objects to the IDocumentActionsArgs.DocumentActions collection. Add two Document Actions to the first Document.

  3. Document Actions act like standard Windows Forms buttons. When creating an Action, you need to specify the execute method that implements the Action's functionality, and (optionally) the canExecute method, which specifies the set of criteria and checks whether or not the current Document meets these criteria. You can specify these methods as shown in the code below.
  4. You now have two Document Actions that act like simple "push" buttons in your first Document. Actions can also act like check buttons that have two states - checked and unchecked. To create these Actions in your second Document, implement the ISupportDocumentActions interface (as you did before) and add two DocumentCheckAction objects to the IDocumentActionsArgs.DocumentActions collection.

    In the code above, two different overloads are used to initialize DocumentCheckAction objects that act differently. Both Actions receive a Boolean variable as the first getState parameter. These variables store a Boolean value depending on the current Action's check state.

    The first Check Action receives the OnToggle method as the last parameter. This method takes a Document as the parameter and is executed each time the Action's check state changes.

    The 'Specific State' Check Action receives two methods - the OnCheck method is called when the Action is checked, and the OnUncheck method is called when the Action is unchecked. This allows you to perform different actions depending on the Action's check state. Compare this to the first Check Action, which performs the same actions whenever its check state changes.

  5. To display the Actions you have added, hide the default PageGroup header. To do so, set the IPageGroupDefaultProperties.ShowPageHeaders property to DefaultBoolean.False.

    The problem is that from now on, end-users can no longer navigate through PageGroup items because there are no page headers. To resolve this issue, add two Document Actions that will implement the navigation functionality. For these Actions, you will handle the WindowsUIView.QueryDocumentActions event. Both Document Actions are added at once, but since only one Document within a PageGroup can be activated, the canExecute method for only one corresponding Action will return true. Thus, both Actions will not be simultaneously visible.

    Note

    The WindowsUIView.QueryDocumentActions event (as well as the ISupportDocumentActions.OnQueryDocumentActions method) occurs only when the Document within a View is activated. Document Actions are most appropriate for PageGroup and Page containers, since only these containers have an activated Document at all times. SplitGroup and SlideGroup containers only have an activated Document in the Detail screen (see the WindowsUIView.ZoomLevel property). Normal and Overview screens for these containers cannot contain any Document Actions. Therefore, it is not recommended to use these Document Actions within these containers.

  6. Finally, the code below illustrates how to add the 'Hello' Document Action. This is an example of an Action that does not have a canExecute method, and thus is displayed within each Content Container.
  7. The animation below shows the result. The Page container has different Actions depending on the activated Document (DocumentActions for the first Document and DocumentCheckActions for the second Document). The PageGroup container also changes its Actions when navigating through its items, and displays either 'Document 1' or 'Document 2' navigation Actions. The 'Hello' action is displayed within any Content Container regardless of the currently activated Document.

Expanded Complete Example Code

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4852.

This example demonstrates how to add How To: Create Custom Document Actions to your WindowsUIView application.

How would you rate this topic?​​​​​​​