WPF: Submitting textbox content

This entry is part 19 of 54 in the series Learn WPF

When we design a web form, we would test out if we could collect the submitted information.

Say now we need to collect some information from the user using a textbox.  We can design a submit button and let the user click on the button to submit the information.

As you can see below, this can be easily done by using tb.Text where tb is the instance name of the TextBox.

<Window x:Class="TextBox1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <TextBox Name="tb" FontSize="16" Height="100">
            Type something here...
        <Button Click="OnClick" FontSize="24" HorizontalAlignment="Stretch" Margin="80,50,80,50">Submit</Button>
        <TextBlock Name="tbl" Text="Text Block" FontSize="24" Height="100"></TextBlock>

using System;
using System.Windows;

namespace TextBox1
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

        private void OnClick(object sender, RoutedEventArgs e)
            String someText = tb.Text;

            tbl.Text = someText;


You can type something in the textbox and after clicking on the submit button, you will see an output similar to below:






Series Navigation<< WPF: object sender
WPF: Radio button >>