locked
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?

    Thanks

    • 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

Answers

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;
    
                InitializeComponent();
            }
            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.

    Thanks


    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?

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/4221c1e9-aa31-4e43-bbd2-2a46e0278dfe/how-to-set-the-default-screen-programmatically-silverlight?forum=lightswitch

    I also noticed this:

    https://connect.microsoft.com/VisualStudio/feedback/details/717087/lightswitch-specifying-startup-form-from-application-loggedin

    "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")
        {
            Application.Current.ShowThisSpecificScreen();
        }
    
        // 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.
    https://social.msdn.microsoft.com/forums/vstudio/en-US/f2384c96-42db-4d2b-94d7-5b691d7beed3/programatically-select-home-screen-html

    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,
    Weiwei

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