Binding Textblock Text and Textbox Text
-
Hello, I am teaching myself xaml and C# and have a question which is probably trivial but I cannot find a resource that is pointing me in the correct direction. If I have a simple app with a copy button, a textblock and a textbox is there a way to bind the textblock text to the entered textbox text? In other words the textblock text is predefined and will not change, once the user enters something in the textbox and hits copy the string copies to the clipboard with the textblock text and the entered textbox text i.e.: What is your age:(this is the textblock static text) 14 years old (entered text in textbox)
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}private void button\_Click(object sender, RoutedEventArgs e) { // I can achieve this with 2 list and a zip then easily building the stringbuilder or string. // Trying to see if a more efficient way to bind the textblock text and textbox entered text in xml } }
-
Hello, I am teaching myself xaml and C# and have a question which is probably trivial but I cannot find a resource that is pointing me in the correct direction. If I have a simple app with a copy button, a textblock and a textbox is there a way to bind the textblock text to the entered textbox text? In other words the textblock text is predefined and will not change, once the user enters something in the textbox and hits copy the string copies to the clipboard with the textblock text and the entered textbox text i.e.: What is your age:(this is the textblock static text) 14 years old (entered text in textbox)
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}private void button\_Click(object sender, RoutedEventArgs e) { // I can achieve this with 2 list and a zip then easily building the stringbuilder or string. // Trying to see if a more efficient way to bind the textblock text and textbox entered text in xml } }
private void button_Click(object sender, RoutedEventArgs e) {
string s = textblock.Text + " " + textbox.Text;
Clipboard.SetText( s );
}(I'd pick better "names" for my controls).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food