-2

I want to a WPF project in c# and I want in my MainWindow interface to add a textbox. I use toolbox to add textBox field and with view code I found the following function:

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{

}

How can I change the default value of the textBox? The only thing the is generated when I add the Textbox was this function. Which variable is responsible for the text? EDIT: I am trying to modify a WPF application which is provided with the kinect SDK. It seems that is not that straight-forward. When I tried to right click on the textBox I cant see any properties option. Inside MainWIndow.xaml.cs there is a line with the property of the textbox:

<TextBox HorizontalAlignment="Left" Height="23" Margin="540,3,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged" Grid.ColumnSpan="3"/>

However I cant find the name of the textbox anywhere.

Jose Ramon
  • 5,572
  • 25
  • 76
  • 152

2 Answers2

1

If you select the textbox and press F4 to access the selected item's properties (normally displayed in the bottom right of the screen), you can set the Text property in the property grid. The value you enter will be used when the form is first created. This is equivalent to setting the Text XAML attribute on the TextBox element.

In code, you can also do this in your constructor using textbox1.Text = "hello"; for instance.

Note, to access the TextBox in code you will need to assign it a name (also via the properties grid).


<TextBox x:Name="textbox1" Text="Default Value Goes Here" HorizontalAlignment="Left" Height="23" Margin="540,3,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged" Grid.ColumnSpan="3"/>
0

The Text property is what holds the value of the textbox.

Textbox1.Text = " ";
Adam
  • 2,422
  • 18
  • 29