Ticket Q298501
Visible to All Users
Duplicate

How to show a View at startup right after the logon window

created 14 years ago (modified 8 years ago)

Hi Guys,
I want to show a dialog view at startup (after logging in). I'm using the
navigationcontroller and in the CustomShowNavigationItem event I'm creating a new listview
as a dialog. After logging in i'm getting a object not referenced error.
Am I doing something wrong?
void ShowDetailViewFromNaviation_CustomShowNavigationItem(object sender, CustomShowNavigationItemEventArgs e)
        {
           if (item != null && item.Id.StartsWith("F_CAB_CD_MAIN_GROUP_TYPE_ListView"))
            {
                createListView(e.ActionArguments.ShowViewParameters, item, typeof(F_CAB_CD_MAIN_GROUP_TYPE));
                e.Handled = true;
            }

}
 private ListView createListView(ShowViewParameters svp, ChoiceActionItem item, Type objType)
        {
            ObjectSpace os = this.Application.CreateObjectSpace() as ObjectSpace;
            var obj = os.CreateObject(objType);
            var v = item.Data as ViewShortcut;
            var lv = this.Application.CreateListView(os, objType, true);
            svp.CreatedView = lv;
            svp.Context = TemplateContext.PopupWindow;
            svp.TargetWindow = TargetWindow.NewModalWindow;
            svp.CreateAllControllers = true;
            DialogController dc = Application.CreateController<DialogController>();
            svp.Controllers.Add(dc);
            return lv;
        }

Comments (3)
Dennis Garavsky (DevExpress) 14 years ago

    Hi Arjan,
    Thank you for your message.
    Your code looks fine in general. Please debug your application and detect on which exactly code line you are getting this exception? Does this error occur in your or in DevExpress code?
    Also, am I right that you first set the StartupNavigatioItem property in the application model and than provide a custom handling of this startup View?
    Feel free to provide your sample project if the provided information does not allow you to determine the cause of the problem yourself.
    Thanks,
    Dennis

      Hi Dennis,
      Does this error occur in your or in DevExpress code?
      >> The error occurs somewhere in the Devexpress code (see log file)
      Also, am I right that you first set the StartupNavigatioItem property in the application model and than provide a custom handling of this startup View?
      >> Yes, that's right

      Dennis Garavsky (DevExpress) 14 years ago

        Hello Arjan,
        Thank you for providing additional information. I will research your problem further and will let you know my results as soon as I can. Please stay tuned!
        Thanks,
        Dennis

        Answers approved by DevExpress Support

        created 14 years ago (modified 2 years ago)

        Hi Arjan,
        Thank you for your patience.
        In the simplest case, you can create a PopupWindowShowAction, configure it to open the required view as usual, and override the module's GetStartupActions method to add the action to the list.

        C#
        using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; ... using System; using System.Collections.Generic; namespace MainDemo.Module { public sealed partial class MainDemoModule : ModuleBase { private PopupWindowShowAction showStartupViewAction; public PopupWindowShowAction ShowStartupViewAction { get { return showStartupViewAction; } } private bool isAccepted = false; public bool IsStartupDialogAccepted { get { return isAccepted; } } public MainDemoModule() { InitializeComponent(); showStartupViewAction = new PopupWindowShowAction(null, "ShowStartupViewAction", ""); showStartupViewAction.CustomizePopupWindowParams += showStartupViewAction_OnCustomizePopupWindowParams; showStartupViewAction.Cancel += action_Cancel; showStartupViewAction.Execute += showStartupViewAction_Execute; } void showStartupViewAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { isAccepted = true; //action execution code... } private void action_Cancel(object sender, EventArgs e) { Application.LogOff(); } public override IList<PopupWindowShowAction> GetStartupActions() { IList<PopupWindowShowAction> result = base.GetStartupActions(); result.Add(showStartupViewAction); return result; } private void showStartupViewAction_OnCustomizePopupWindowParams(Object sender, CustomizePopupWindowParamsEventArgs args) { IObjectSpace objectSpace = showStartupViewAction.Application.CreateObjectSpace(typeof(Contact)); args.View = showStartupViewAction.Application.CreateListView(objectSpace, typeof(Contact), true); isAccepted = false; } ... } }

        We use the same approach to the ChangePasswordOnLogon Action of our Security module (…\DevExpress.ExpressApp.Modules\DevExpress.ExpressApp.Security\Module.cs ).
        You can find more suitable solutions for this task in the How to show a specific View at application startup, right after the logon window article.

        Outdated solution description
        To go back to the logon dialog when the custom dialog is canceled in WinForms, you need to override the LogOff method and reimplement the Start method in the WinApplication descendant as follows:

        C#
        private T Invoke<T>(string methodName, params object[] args) { return (T)typeof(WinApplication).GetMethod(methodName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(this, args); } private T GetField<T>(string fieldName) { return (T)typeof(WinApplication).GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this); } public new void Start() { bool exit = false; while (!exit) { try { Tick.In("WinApplication.Start()"); Invoke<object>("GuardRecursiveUpdate"); Invoke<object>("DoLogon"); if (!GetField<bool>("isApplicationUpdate") && IsLoggedOn) { try { ProcessStartupActions(); if (!IsLoggedOn) continue; if (!GetField<bool>("exiting")) { StartSplash(); ShowStartupWindow(); } else { return; } } finally { StopSplash(); } Tracing.Tracer.LogSeparator("Application startup done"); Tracing.Tracer.LogSeparator("Application running"); Tick.Out("WinApplication.Start()"); DoApplicationRun(); if (!ignoreUserModelDiffs) { SaveModelChanges(); } } } catch (Exception e) { HandleException(e); } finally { Invoke<bool>("LogOffCore", false); } Tracing.Tracer.LogSeparator("Application stopping"); exit = true; } } public override void LogOff() { //base.LogOff(); if (Invoke<bool>("LogOffCore", true)) { bool exit = false; while (!exit) { Invoke<object>("DoLogon"); if (!this.isLoggedOn) { System.Windows.Forms.Application.Exit(); return; } try { this.ProcessStartupActions(); if (!IsLoggedOn) continue; this.StartSplash(); this.ShowStartupWindow(); } finally { this.StopSplash(); } exit = true; } } }

        To cancel the dialog when the dialog window is simply closed, add the following code to the WinForms module:

        C#
        public sealed partial class MainDemoWinModule : ModuleBase { ... public override void Setup(ApplicationModulesManager moduleManager) { base.Setup(moduleManager); var module = ModuleManager.Modules.FindModule<MainDemoModule>(); module.ShowStartupViewAction.CustomizeTemplate += showStartupViewAction_CustomizeTemplate; } void showStartupViewAction_CustomizeTemplate(object sender, CustomizeTemplateEventArgs e) { var form = e.Template as System.Windows.Forms.Form; if (form != null) { form.FormClosing += form_FormClosing; } } void form_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) { var module = ModuleManager.Modules.FindModule<MainDemoModule>(); if(!module.IsStartupDialogAccepted){ module.ShowStartupViewAction.RaiseCancel(); } } }
          Show previous comments (8)
          DevExpress Support Team 9 years ago

            Thanks for your feedback.
            As for moving this entire code to the platform-agnostic module, this doesn't look as a good idea since the code contains references to platform specific classes (e.g. System.Windows.Forms.Form).

              Michael,
              To further implement your suggestion,
              If all of the code in showStartupViewAction is reusable except only showStartupViewAction_CustomizeTemplate to avoid form closing problem in WinForm only, How can I reuse then same showStartupViewAction across projects and override just showStartupViewAction_CustomizeTemplate in WinForm only and keep everything else in the Module Project? If it is not possible then I have to decide between keeping one business logic and let some of the platform-specific code in the platform-agnostic one, or , duplicate the business logic to both projects having its platform-specific code stay in its appropriate area.
              Thank you.

              DevExpress Support Team 9 years ago

                You move platform-specific code to the platform-specific module if you expose the action and the flag via module variables. To get the module from another module, use the ModuleManager.Modules.FindModule<T>() method.
                I have updated the original answer to demonstrate this approach.

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.