Comparing the functionality of my previous changes to the Microsoft provided bing app again, I noticed some subtle changes. I won't go into all of the details here because it's boring and tedious, but I changed my Textboxes so that they wouldn't clear out the values every time they were clicked (unless the values shown are the default values). Rather, upon clicking, they highlight the entire box for easy editing. Also, the default format is greyed out while any user submitted input is black. The changes are a big deal to me but probably very boring to anyone else reading this.
Just to illustrate, now here are screenshots:
I removed any EventRaisers in my XAML code and moved it all to the code-behind. I'm starting to develop more of an understanding of EventRaisers, Events, EventHandlers, Delegates, etc., enough to get my implementation working, but I still feel like I'm not doing things the "proper" way or following good design patterns in my code (MVVM????) For right now, I'm just trying to get the thing working and as I understand more as I go along, I can clean it up and do things the "proper" way.
However, I'm glad to say that when it comes to entering user input and deleting user input in the Textboxes, my app works the same as the bing app. (Yes, I tested for null input too. It works!)
Here are some snippets of my code that implement the text input.
In my MainPage class:
const string DEFAULT_TXT = "Expense";
static string current_txt = DEFAULT_TXT;
static bool txt_default_settings = true;
static string current_txt = DEFAULT_TXT;
static bool txt_default_settings = true;
In the constructor for my MainPage class:
txtInput.GotFocus += txtInput_GotFocus;
txtInput.LostFocus += txtInput_LostFocus;
And some event handlers:txtInput.LostFocus += txtInput_LostFocus;
private void txtInput_GotFocus(object sender, RoutedEventArgs e) {
txtInput.Foreground = new SolidColorBrus(Colors.Black);
if (txt_default_settings) {
txtInput.Text = "";
}
else {
txtInput.SelectAll();
}
}
private void txtInput_LostFocus(object arg1, RoutedEventArgs arg2) {
if (txtInput.Text == String.Empty) {
txtInput.Foreground = new SolidColorBrush(Colors.Gray);
txtInput.Text = DEFAULT_TXT;
current_txt = DEFAULT_TXT;
txt_default_settings = true;
}
else {
txtInput.Foreground = new SolidColorBrush(Colors.Black);
txt_default_settings = false;
current_txt = txtInput.Text.Trim();
}
}
txtInput.Foreground = new SolidColorBrus(Colors.Black);
if (txt_default_settings) {
txtInput.Text = "";
}
else {
txtInput.SelectAll();
}
}
private void txtInput_LostFocus(object arg1, RoutedEventArgs arg2) {
if (txtInput.Text == String.Empty) {
txtInput.Foreground = new SolidColorBrush(Colors.Gray);
txtInput.Text = DEFAULT_TXT;
current_txt = DEFAULT_TXT;
txt_default_settings = true;
}
else {
txtInput.Foreground = new SolidColorBrush(Colors.Black);
txt_default_settings = false;
current_txt = txtInput.Text.Trim();
}
}
I think now my next goal is to display a separate page that lists the expenses when the "Display" button is clicked, instead of tons of MessageBoxes flashing across the screen like it does now.