开发者

How to show Splash Screen and Login Screen before loading the Actual Shell using PRISM?

开发者 https://www.devze.com 2023-03-31 18:48 出处:网络
I need to show the Splash Screen when user clicks on the Application for say 3 seconds and after that I have to show the Login Screen for the Credential verification. If it is a valid user then only t

I need to show the Splash Screen when user clicks on the Application for say 3 seconds and after that I have to show the Login Screen for the Credential verification. If it is a valid user then only the ap开发者_高级运维plication main Shell should load. How to accomplish this task?


for the splash screen you will simply Add New Item / Splash Screen. a .png file will be added to your project , you are then free to edit it or replace it with another .png file with the same name.

for the login screen, ShowDialog() it on your Main Window viewmodel constructor, then handle the close event of the login Window to shutdown the application if user not verified and to just close if the user verified ( I'm using a static class to save global values, like the user Id, depends on it I choose wheather to shutdown the application or to let it load ) , it varies how one would implement ShowDialog() and Close() methods in the viewModel, I suppose you already figured it out, see this viewmodel of my Login Window

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using GlassStoreBLL;
using System.Windows;

namespace GlassStore.ViewModels
{
class LoginViewModel:ViewModelBase
{
    private String _UserName;
    private String _Password;
    private String _richMessage;
    private Commands.RelayCommand _login;
    private Commands.RelayCommand _closing;
    private IDialogueService _dialogService;
    private String _errorMessage;

    public LoginViewModel() : this(new DialogueService()) { }
    public LoginViewModel(IDialogueService dialogueService)
    {
        _dialogService = dialogueService;
        GlobalClass.userID = 0;
    }

    public String richMessage
    {

        get { return _richMessage; }
        set
        {
            if (_richMessage != value)
            {
                _richMessage = value;
                OnPropertyChanged("richMessage");
            }
        }
    }

    public String Password
    {
        get { return _Password; }
        set
        {
            if (_Password != value)
            {
                _Password = value;
                OnPropertyChanged("Password");
            }
        }
    }

    public String UserName
    {
        get { return _UserName; }
        set
        {
            if (_UserName != value)
            {
                _UserName = value;
                OnPropertyChanged("UserName");
            }
        }
    }

    public String errorMessage
    {
        get { return _errorMessage; }
        set
        {
            if (_errorMessage != value)
            {
                _errorMessage = value;
                OnPropertyChanged("errorMessage");
            }
        }
    }




    public ICommand login
    {
        get
        {
            if (_login == null)
            {
                _login = new Commands.RelayCommand(param => CanLogin(), param => Login());
            }

            return _login;
        }
    }

    public ICommand closing
    {
        get
        {
            if (_closing == null)
            {
                _closing = new Commands.RelayCommand(param => CanClosing(), param => Closing());
            }

            return _closing;
        }
    }

    private bool CanClosing()
    {
        return true;
    }

    private void Closing()
    {
        if (GlobalClass.userID == 0)
        {
            Application.Current.Shutdown();
        }
        else
        {

        }
    }

    private bool CanLogin()
    {
        return !String.IsNullOrEmpty(UserName) && !String.IsNullOrEmpty(Password);
    }

    private void Login()
    {
        try
        {
            User usr1 = new User();
            usr1 = usr1.userExists(UserName, Password);
            if (usr1.id == 0)
            {
                errorMessage = "اسم المستخدم أو كلمة السر أو الاثنان خطأ";
            }
            else
            {

                GlobalClass.userID = usr1.id;

                if (usr1.manager == "true")
                {
                    GlobalClass.manager = true;
                }
                else
                {
                    GlobalClass.manager = true;
                }


                var windows = Application.Current.Windows;
                for (var i = 0; i < windows.Count; i++)
                {
                    if (windows[i].DataContext == this)
                        _dialogService.Close(windows[i]);
                }
            }
        }
        catch (Exception d)
        {
            errorMessage = "خـطـأ";
            richMessage = d.Message;
        }
    }
}
}


If you want to show the LoginDialog BEFORE the Shell is loaded, you have to create your own Bootstrapper which inhertis from the prism Bootstrapper and call the LoginDialog.ShowDialog() method in the CreateShell() (or InitializeShell()) method of the Bootstrapper

0

精彩评论

暂无评论...
验证码 换一张
取 消