Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this XAML code...

XML
<Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="74,78,0,0" x:Name="textBox1" VerticalAlignment="Top" Width="120" />
        <Button x:Name="button1" Content="A" Height="23" HorizontalAlignment="Left" Margin="12,156,0,0"  VerticalAlignment="Top" Width="75"  Click="button1_Click"></Button>
        <Button x:Name="button2" Content="B" Height="23" HorizontalAlignment="Left" Margin="93,156,0,0"  VerticalAlignment="Top" Width="75" Click="button1_Click"></Button>
        <Button x:Name="button3" Content="C" Height="23" HorizontalAlignment="Left" Margin="174,156,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button x:Name="button4" Content="D" Height="23" HorizontalAlignment="Left" Margin="12,200,0,0"  VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button x:Name="button5" Content="E" Height="23" HorizontalAlignment="Left" Margin="185,228,0,0" VerticalAlignment="Top" Width="75"  Click="button1_Click" />
    </Grid>

C#




And this XAML.CS code.....

C#
private void button1_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            button.Content.ToString();

            textBox1.Text = button.Content.ToString();

         }


Now, when I press the button, only one character is being displayed. Still using my current XAML.CS code, how do continue from here in order to get multiple characters when the buttons are pressed multiple times??
Posted
Comments
Sergey Alexandrovich Kryukov 20-Feb-14 23:19pm    
Aha, button.Content.ToString() is written twice, first one goes nowhere. Congratulations! :-)
—SA

1 solution

What you are doing is replacing the text using
textBox1.Text = button.Content.ToString();<br />

Try something like textBox1.Text = textBox1.Text + Convert.ToString(button.Content);
 
Share this answer
 
Comments
Alif Marz 11-Feb-14 2:42am    
Thanks Pankaj Nikam. Now it works!!
Pankaj Nikam 11-Feb-14 4:47am    
You are most welcome :)
Please mark this as answer if it helps you.
Sergey Alexandrovich Kryukov 20-Feb-14 23:18pm    
Event though the solution is trivial, my 5 just for sorting out such gibberish... :-)
—SA
Pankaj Nikam 21-Feb-14 6:26am    
Thanks a lot @Sergey Alexandrovich Kryukov :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900