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. WPF
  4. Set the Text property of a TextBox

Set the Text property of a TextBox

Scheduled Pinned Locked Moved WPF
helpjsonquestion
5 Posts 3 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.
  • S Offline
    S Offline
    soup
    wrote on last edited by
    #1

    Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon

    C J 2 Replies Last reply
    0
    • S soup

      Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is a WPF project ? Do you have any events on the other textbox that might fire and change or reject the text ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • C Christian Graus

        This is a WPF project ? Do you have any events on the other textbox that might fire and change or reject the text ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        S Offline
        S Offline
        soup
        wrote on last edited by
        #3

        Yeah, this is WPF. I know what you mean, but I don't set the Text property anywhere else or set e.Handled to true or false anywhere. When I set the Text property, TextChanged fires on that TextBox as normal. In that handler, I read the value out to use it for other purposes. All this code does run ok, but visually, it's as if nothing happened! This is odd. I'm going to try and create a simple WPF app with 2 TextBoxes and do something similar. If you have any other ideas, I'd love to hear them. :)

        1 Reply Last reply
        0
        • S soup

          Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon

          J Offline
          J Offline
          Jeremy Hutchinson
          wrote on last edited by
          #4

          Are you setting the text property of TextBox1, or are you updating property to which the Text property of TextBox1 is bound? If you are updating a property the problem is likely that you need to raise an OnPropertyChanged event for that property. You'll have to implement INotifyPropertyChange...

          S 1 Reply Last reply
          0
          • J Jeremy Hutchinson

            Are you setting the text property of TextBox1, or are you updating property to which the Text property of TextBox1 is bound? If you are updating a property the problem is likely that you need to raise an OnPropertyChanged event for that property. You'll have to implement INotifyPropertyChange...

            S Offline
            S Offline
            soup
            wrote on last edited by
            #5

            Hi, I am using binding a fair bit, but in this particular case, this textbox is not bound to anything. I am merely doing the following: myTextBox.Text = "some text"; I am getting some bizarre feeling that WPF is preventing the visual change based on some form of focus or caret permission type thing, but I can't be convinced of this. It's an odd one at the moment.

            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