I just recently started learning Windows Phone 7 development, C# and Silverlight. I’m making a Morse Code Translator as an exercise but I ran into a problem. I made three buttons for the user to input morse code into a TextBox. One is for period, the second is for line and the last one is for space. The problem is that I can’t seem to input more than one character into the TextBox using this method and they simply overwrite each other.
Here’s how I tried to do it in the click event.
private void bShort_Click(object sender, RoutedEventArgs e)
{
char dot = ".";
TBoxMorse2.Text = dot.ToString();
}
How should I go fixing this problem?
Sorry if this has been asked. I tried to search for it but didn’t find any similar problems here on StackOverflow.
Thank you all in advance for checking this out!
You’re explicitly overwriting the value:
By setting the property, you overwrite anything that’s already in there. You don’t want to set the property to the new value. You want to set it to the existing value plus the new value:
As usual, there are multiple ways to do it.
Side note, your
TBoxMorse2variable name isn’t considered idiomatic C#. (As implied by the syntax highlighter on StackOverflow incorrectly highlighting it as a Type instead of a Variable.) C# convention prefers that variable names don’t begin with a capital letter. Something like this: