Пример #1
0
 private async void btnTest1_Click(object sender, RoutedEventArgs e)
 {
     CustomMessageBox dlg = new CustomMessageBox("Do you like Material Design?", "Yea!", "Nope!");
     int result = (int)await DialogHost.Show(dlg);
     switch (result)
     {
         case 1:
             // do things
             break;
         case 2:
             // do things
             break;
     }
 }
        private void OnLoginButtonClick(object sender, RoutedEventArgs e)
        {
            var postData = "grant_type=password";
            postData += "&username="******"&password="******"http://localhost:28499/Token");
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            var responseString = string.Empty;
            try
            {
                var response = (HttpWebResponse)request.GetResponse();
                responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (responseString != "")
            {
                var chatWindow = new ChatWindow(this.UserName.Text);
                chatWindow.Show();
                this.Close();
            }
            else
            {
                var messageBox = new CustomMessageBox("Invalid user name or password");
                messageBox.ShowDialog();
                this.UserName.Text = "";
                this.Password.Password = "";
            }
        }