Exemple #1
0
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            UsernameTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();

            var avatarIndex = _model.AvatarIndex;
            var username    = UsernameTextBox.Text;

            var mainWindow = Application.Current.MainWindow as MainWindow;

            if (string.IsNullOrEmpty(username) || mainWindow == null ||
                mainWindow.FindName("UsersListBox") is ListBox usersListBox &&
                usersListBox.Items.Cast <UserViewModel>().Select(user => user.Username).Contains(username))
            {
                return;
            }

            mainWindow.Model.Users.Add(new UserViewModel(username, avatarIndex));

            var json = JsonConvert.SerializeObject(mainWindow.Model.Users, Formatting.Indented);

            File.WriteAllText("users.json", json);

            Close();
        }
Exemple #2
0
 private void SaveLoginDataButtonTapped(object sender, TappedRoutedEventArgs e)
 {
     UsernameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
     APIKeyTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
 }