How to setup a start screen programmatically in Silverlight? RRS feed

  • Question

  • Hello,

    Does anyone know how to set a startup screen dynamically using code in silverlight (lightswitch) application?


    • Moved by Weiwei CaiModerator Friday, July 10, 2015 6:40 AM This issue is more related to LightSwitch
    Thursday, July 9, 2015 3:19 PM


All replies

  • I work with Silverlight, never used lightswitch.

    Maybe it's the same though.

    In Silverlight you have app.xaml.cs.

    In an example of mine I have roughly:

        public partial class App : Application
            public App()
                Startup += Application_Startup;
                Exit += Application_Exit;
                UnhandledException += Application_UnhandledException;
            private void Application_Startup(object sender, StartupEventArgs e)
                RootVisual = new MainPage();
    MainPage is the first thing loaded into Silverlight, so you'd put some logic in there to decide which to show if you wanted to show a different page.

    Thursday, July 9, 2015 3:36 PM
  • Thanks Andy for the reply.

    With lightswitch it is a bit different. It has Application class in which there are 2 methods in which we can write the code which we need to run at the application startup. Those are "Application_Initialize" and "Application_LoggedIn".

    I have put my code in there which is as below:

    if (User.HasPermission(Permissions.SecurityAdministration)) Application.Current.ShowWelcome();            
    else                Application.Current.ShowMerchantOrderEntry();

    These are 2 different screens "Welcome" and "MerchantOrderEntry" either of which needs to be displayed according to the permissions. However, none of them is getting displayed and I am getting the blank screen.

    Please let me know if you have any workaround for the same.


    Thursday, July 9, 2015 4:27 PM
  • It seems it's quite different.

    Did you also go the screen navigation settings page and clear the current startup screen?


    I also noticed this:


    "Instead of using the Application_LoggedIn event, place your logic in the _Run method of the default screen.  While this is not ideal, this does provide a workaround.  You may even want to create a default screen for the sole purpose of executing this logic.  Here is an example, with a default screen named “Home”:"

    partial void Home_Run(ref bool handled)
        // place your logic for determining which screen to display here:
        if (Application.Current.User.FullName == "SomeUserName")
        // this must be set to true so that the this screen is not also displayed
        handled = true;

    • Proposed as answer by Xpert360 Friday, July 10, 2015 7:13 AM
    • Marked as answer by Angie Xu Thursday, July 16, 2015 1:56 AM
    Thursday, July 9, 2015 7:37 PM
  • Hi develothon87,

    Please refer to following link which introduce how to select home screen programmatically. Hope it can help you.

    Since this issue is more related to LightSwitch. I move it to the LightSwitch forum. It is appropriate and more experts will assist you.

    Best Regards,

    Friday, July 10, 2015 6:39 AM
  • Thanks Weiwei
    Friday, July 24, 2015 4:02 PM