Scenario
One may want to show a dialog view at startup (after logging in). Typically, this view appears after the successful logon and allows a user to select or edit personal or global settings such as current password, company, currency, language, etc. Also, it may be often required to display this View as modal before a user can access the navigation menu or any other forms in the application. In other scenarios, it may be required to display a kind of notifications popup right after loading the main window, with unread messages, active orders, etc.
Solutions
Consider one of the following approaches depending on your business requirements:
1. If the View to be shown is also available in the navigation control
Set the corresponding navigation item as startup via the Application Model's NavigationItems | StartupNavigationItem property. Note that if your navigation item is supposed to show a DetailView for a specific object instance, it is necessary to additionally specify the IModelNavigationItem > ObjectKey property via the Model Editor or in code, as described at Automatically display view at the first time running application.
2. If the View to be shown may not necessarily be added into the navigation control by default
Override the GetStartupActions method of your ModuleBase descendant to return a PopupWindowShowAction that opens the desired view. Note that with this approach a View will always be shown as modal dialog prior to showing the main application form.
In our code, the SecurityModule > ChangePasswordOnLogonAction that shows the "Change password on first logon" dialog is used in the aforementioned virtual method.
3. If the methods above are not applicable or there are other custom requirements (the most universal approach)
3.1. Displaying a non-popup View embedded inside the main window
Subscribe to the ShowNavigationItemController.CustomShowNavigationItem event to display a View with required settings specified via the e.ActionArguments.ShowViewParameters property. Refer to the How to show a window ( View ) representing data in XAF article for examples for different view types. For instance, you can consider the following WindowController:
C#using DevExpress.ExpressApp;
using MainDemo.Module.BusinessObjects;
using DevExpress.ExpressApp.SystemModule;
namespace MainDemo.Module.Controllers {
public class ShowCustomStartupNavigationItemController : WindowController {
private ShowNavigationItemController navigationController;
public ShowCustomStartupNavigationItemController() {
TargetWindowType = WindowType.Main;
}
protected override void OnActivated() {
base.OnActivated();
navigationController = Frame.GetController<ShowNavigationItemController>();
if(navigationController != null) {
navigationController.CustomShowNavigationItem += OnCustomShowNavigationItem;
}
}
void OnCustomShowNavigationItem(object sender, CustomShowNavigationItemEventArgs e) {
navigationController.CustomShowNavigationItem -= OnCustomShowNavigationItem;//It is important to unsubscribe from this event immediately.
ShowViewParameters svp = e.ActionArguments.ShowViewParameters;
IObjectSpace os = Application.CreateObjectSpace(typeof(Contact));
object theObjectToBeShown = os.FindObject<Contact>(null);
DetailView dv = Application.CreateDetailView(os, theObjectToBeShown, true);
dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
svp.CreatedView = dv;
e.Handled = true;
}
protected override void OnDeactivated() {
navigationController.CustomShowNavigationItem -= OnCustomShowNavigationItem;
base.OnDeactivated();
}
}
}
3.2. Displaying a separate popup/modal window after the main window was shown
Popup windows can be displayed at a custom moment through the ShowViewStrategyBase.ShowViewInPopupWindow method. To execute this method after the startup View is shown in the main window, use the following platform-specific solutions:
ASP.NET WebForms:
C#using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Web;
using DevExpress.ExpressApp.Web.SystemModule;
using MainDemo.Module.BusinessObjects;
namespace MainDemo.Module.Web {
public class CustomWebShowStartupNavigationItemController : WebShowStartupNavigationItemController {
protected override void ShowStartupNavigationItem() {
base.ShowStartupNavigationItem();
//Prior to 18.1
//WebWindow.CurrentRequestPage.LoadComplete += (s, e) => {
IObjectSpace os = Application.CreateObjectSpace(typeof(Contact));
object theObjectToBeShown = os.FindObject<Contact>(null);
DetailView dv = Application.CreateDetailView(os, theObjectToBeShown, true);
dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
Application.ShowViewStrategy.ShowViewInPopupWindow(dv);
//};
}
}
}
WinForms:
C#using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.Win.SystemModule;
using MainDemo.Module.BusinessObjects;
using System.Windows.Forms;
namespace MainDemo.Module.Win {
public class CustomWinShowStartupNavigationItemController : WinShowStartupNavigationItemController {
protected override void ShowStartupNavigationItem(ShowNavigationItemController controller) {
base.ShowStartupNavigationItem(controller);
((WinWindow)Application.MainWindow).Form.BeginInvoke(new MethodInvoker(() => {
IObjectSpace os = Application.CreateObjectSpace(typeof(Contact));
object theObjectToBeShown = os.FindObject<Contact>(null);
DetailView dv = Application.CreateDetailView(os, theObjectToBeShown, true);
dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
Application.ShowViewStrategy.ShowViewInPopupWindow(dv);
}));
}
}
}
NOTE: It is important to specify the IModelRootNavigationItems > StartupNavigationItem property (e.g., set it to MyDetails or another suitable item) for these solutions to work properly.
To learn more, refer to the Ways to Show a View topic.
If neither of these solutions meets your needs, please submit a separate ticket and describe your business requirements in greater detail so that we can look for other options for you.
How to set size of popup window to maximize in last example for winform ?
Hello,
I've created a separate ticket on your behalf (T695689: How to set size of popup window). It has been placed in our processing queue and will be answered shortly.
Thanks,
Andrey