private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            iconLoad.Visibility = Visibility.Visible;
            btnLogin.IsEnabled  = false;
            if (chkSafePW.IsChecked == true)
            {
                Properties.Settings.Default.SafePW   = true;
                Properties.Settings.Default.UserName = txbUser.Text;
                Properties.Settings.Default.Password = SecurePasswordVault.EncryptString(SecurePasswordVault.ToSecureString(txbPass.Password));
                Properties.Settings.Default.Save();
            }
            else
            {
                Properties.Settings.Default.SafePW   = false;
                Properties.Settings.Default.UserName = "";
                Properties.Settings.Default.Password = "";
                Properties.Settings.Default.Save();
            }

            //userlogin
            bool result = await RestClient.LoginAndGetSession(txbUser.Text, txbPass.Password);

            if (result == true)
            {
                this.DialogResult = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("Login mislukt. Kloppen je gegevens?");
            }
            iconLoad.Visibility = Visibility.Hidden;
            btnLogin.IsEnabled  = true;
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                txbStudFulter.TextChanged += TextBox_TextChanged;
                if (Properties.Settings.Default.SafePW == true)
                {
                    string user  = Properties.Settings.Default.UserName;
                    string pass  = SecurePasswordVault.ToInsecureString(SecurePasswordVault.DecryptString(Properties.Settings.Default.Password));
                    var    gotit = await RestClient.LoginAndGetSession(user, pass);

                    if (gotit != true) //Login vereist
                    {
                        LoadLoginAndQuitIfNeeded();
                    }
                }
                else //Login vereist
                {
                    LoadLoginAndQuitIfNeeded();
                }



                timerRefresh.Interval  = new TimeSpan(0, 0, 15);
                timerRefresh.Tick     += (p, ex) => { DownloadActiveSessions(); };
                timerRefresh.IsEnabled = true;
                RefreshDataFromServer();
            }
            catch (Exception ex)
            {
                await this.ShowMessageAsync("Error bij Window_Loaded", " Error=" + ex.Message);
            }
        }
 private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (Properties.Settings.Default.SafePW == true)
     {
         chkSafePW.IsChecked = true;
         txbUser.Text        = Properties.Settings.Default.UserName;
         txbPass.Password    = SecurePasswordVault.ToInsecureString(SecurePasswordVault.DecryptString(Properties.Settings.Default.Password));
     }
 }