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. binding with timer

binding with timer

Scheduled Pinned Locked Moved WPF
questionwpfwcf
4 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.
  • M Offline
    M Offline
    michaelgr1
    wrote on last edited by
    #1

    Hello, I have a textBox which has binding to a property of a ViewModel. I want the ViewModel to execute a method if the textbox is not empty and if user didn't change the text in the textbox for 2 seconds. I mean only if user wrote something and waited for 2 seconds, than the method will execute. How can i do it?

    M 1 Reply Last reply
    0
    • M michaelgr1

      Hello, I have a textBox which has binding to a property of a ViewModel. I want the ViewModel to execute a method if the textbox is not empty and if user didn't change the text in the textbox for 2 seconds. I mean only if user wrote something and waited for 2 seconds, than the method will execute. How can i do it?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Have a timer in the VM Have the onchange event in the model for the field reset the timer (and clear the cache string, possibly) In the tick method check the content of the field if != string.empty and matches the cached string then call your method Cache the string Onchange of the selected item always clear the cache string

      Never underestimate the power of human stupidity RAH

      S 1 Reply Last reply
      0
      • M Mycroft Holmes

        Have a timer in the VM Have the onchange event in the model for the field reset the timer (and clear the cache string, possibly) In the tick method check the content of the field if != string.empty and matches the cached string then call your method Cache the string Onchange of the selected item always clear the cache string

        Never underestimate the power of human stupidity RAH

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

        Sounds like too much work. When he adds a 2nd edit box / timer, he'll have to copy & paste all that crap. Better solution would be to write a "TextBoxEx" control that encapsulates the behavior so it is easier to reuse and you don't have to dick around with forwarding a bunch of stuff to the VM.

        M 1 Reply Last reply
        0
        • S SledgeHammer01

          Sounds like too much work. When he adds a 2nd edit box / timer, he'll have to copy & paste all that crap. Better solution would be to write a "TextBoxEx" control that encapsulates the behavior so it is easier to reuse and you don't have to dick around with forwarding a bunch of stuff to the VM.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          SledgeHammer01 wrote:

          When he adds a 2nd edit box / timer

          Only applies if this rather esoteric requirement needs to be duplicated, but yes I think I'd do with the textboxex out of good design principles (never write code twice)

          Never underestimate the power of human stupidity RAH

          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