Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Binding Textblock Text and Textbox Text

Binding Textblock Text and Textbox Text

Scheduled Pinned Locked Moved C#
questionwpfcsharpwcfxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mnkdrt
    wrote on last edited by
    #1

    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
        }
    }
    
    L 1 Reply Last reply
    0
    • M mnkdrt

      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
          }
      }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups