Log In
[Expand]General Information
[Expand]WinForms Controls
[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]Report Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
 [Expand]Design-Time Features
 [Expand]Functional Testing
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
    How to: Access Navigation Control
    How to: Access the Navigation Dock Panel (in a WinForms Application)
    How to: Access the Office Navigation Bar
    How to: Access the Transition Manager
    How to: Create a New Object using the Navigation Control
    How to: Implement Custom Context Navigation
  [Expand]List Editors
  [Expand]Property Editors
  [Expand]Scheduler and Notifications
  [Expand]Miscellaneous UI Customizations
 [Expand]Frequently Asked Questions
 [Expand]API Reference
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
[Expand]End-User Documentation

How to: Create a New Object using the Navigation Control

In this topic, you will see how to execute custom code when a specific Navigation Item is clicked. A Navigation Item that triggers the NewObjectViewController.NewObjectAction Action execution will be added to the navigation control.

Show Me

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

In this example, the following Issue persistent class will be used for demo purposes. You can use any other persistent class from your existing application instead.

To add the Create New Issue... navigation item, run the Model Editor in the module project by double-clicking the Model.DesignedDiffs.xafml file. Locate the Issue navigation item node and add a new node to the same navigation group. Set the IModelBaseChoiceActionItem.Id property to NewIssue, the IModelBaseChoiceActionItem.Caption property to Create New Issue..., the IModelBaseChoiceActionItem.ImageName property to Action_New and the IModelNavigationItem.View property to Issue_DetailView. To learn more about creating navigation items in the Model Editor, refer to the Add an Item to the Navigation Control topic.

To specify the code to be executed when the Create New Issue... navigation item is clicked, inherit from the WindowController class, override the OnActivated method, and subscribe to the ShowNavigationItemController.CustomShowNavigationItem event. Use the Frame.GetController<ControllerType> method to access the ShowNavigationItemController instance. In the CustomShowNavigationItem event handler, access the current navigation item identifier using the CustomShowNavigationItemEventArgs.ActionArguments parameter. If the identifier is "NewIssue", call the SingleChoiceAction.DoExecute method of the NewObjectViewController.NewObjectAction Action. Pass the ChoiceActionItem instance associated with the Issue object type to the DoExecute method. As a result, the New Action will be executed and the empty Issue Detail View will be displayed. Since the navigation control is displayed in the main Window only, the created Controller should target the main Window as well. Thus, set the WindowController.TargetWindowType property to Main in the Controller's constructor.


Instead of using the New Action to perform this task, you can create a new Object Space, Task object and Task Detail View. However, in this case, you will need to duplicate the functionality implemented in the New Action and its Controller.

You can now run the WinForms and ASP.NET applications to check if the Issue objects can be created via the Create New Issue... navigation item (see the screenshot at the beginning of this topic). However, if you enable the Multiple Document Interface (MDI) mode in the WinForms application (see MdiShowViewStrategy), you will notice that the implemented NewObjectFromNavigationController Controller does not support this mode. The reason is that in the code above, the NewObjectViewController is inactive because it is obtained from the main Window, which does not display a View in MDI mode. The solution is to take the active child MDI window and obtain the NewObjectViewController from it. The NewObjectFromNavigationController is implemented in the platform-agnostic module, so you cannot add WinForms-specific code to it. Thus, move the code that gets the New Action to the virtual GetNewObjectAction method.

When all MDI windows are closed, the GetNewObjectAction will be unable to return the New Action, so add a workaround code that creates an Issue and displays its Detail View for this situation.

Then, inherit the NewObjectFromNavigationController in the WinForms module project and override the GetNewObjectAction method. In the overridden method, check to see if the WinApplication.ShowViewStrategy property returns an object of the MdiShowViewStrategy type. If this is the case, get the active child MDI window via the MdiShowViewStrategy.GetActiveInspector method, and get the New Action from this Window using the Frame.GetController<ControllerType> method. Otherwise, call the base Controller's GetNewObjectAction method.

To test the code above, enable the MDI mode via the IModelOptionsWin.UIType property in the Model Editor (see Choose the WinForms UI Type).

Expanded See Also

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