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. Unselect text in textbox on textbox lostfocus event.

Unselect text in textbox on textbox lostfocus event.

Scheduled Pinned Locked Moved WPF
csharpwpf
4 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.
  • P Offline
    P Offline
    pc rajesh singh
    wrote on last edited by
    #1

    I am working in WPF. Normally on lost focus of textbox , text are unselected. But if I set the value e.handled = true on lostfocus event handler, unselection doesn't happen. I need to set e.handled = true to prevent the event from bubbling up. Note: I am not stopping from lostfocus being triggered. LostFocus takes place, its just that, automatic unselection doesn't happen and I want the unselection to take place. Private Sub MyTextBox_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub

    S 1 Reply Last reply
    0
    • P pc rajesh singh

      I am working in WPF. Normally on lost focus of textbox , text are unselected. But if I set the value e.handled = true on lostfocus event handler, unselection doesn't happen. I need to set e.handled = true to prevent the event from bubbling up. Note: I am not stopping from lostfocus being triggered. LostFocus takes place, its just that, automatic unselection doesn't happen and I want the unselection to take place. Private Sub MyTextBox_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub

      S Offline
      S Offline
      sivaddrahcir
      wrote on last edited by
      #2

      Try setting the TextBox.SelectionLength property to 0 in your LostFocus handler method.

      Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com

      P 1 Reply Last reply
      0
      • S sivaddrahcir

        Try setting the TextBox.SelectionLength property to 0 in your LostFocus handler method.

        Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com

        P Offline
        P Offline
        pc rajesh singh
        wrote on last edited by
        #3

        Well setting that only leaves the textedit cursor blinking in the text box even after lost focus. I have already tried via default selection property settings e.g selectionlength or selectionstart, all results in setting the cursor blinking in the text box even if the next control get focus. Just tab through the text box and see the behviour of the cursor on txtFirst and txtSecond < textbox x:name="txtTest" lostfocus="txtFirst_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtFirst" lostfocus="txtFirst_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtSecond" lostfocus="txtSecond_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtFourth" xmlns:x="#unknown" / > Private Sub txtFirst_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub Private Sub txtSecond_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub

        S 1 Reply Last reply
        0
        • P pc rajesh singh

          Well setting that only leaves the textedit cursor blinking in the text box even after lost focus. I have already tried via default selection property settings e.g selectionlength or selectionstart, all results in setting the cursor blinking in the text box even if the next control get focus. Just tab through the text box and see the behviour of the cursor on txtFirst and txtSecond < textbox x:name="txtTest" lostfocus="txtFirst_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtFirst" lostfocus="txtFirst_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtSecond" lostfocus="txtSecond_LostFocus" xmlns:x="#unknown" / > < textbox x:name="txtFourth" xmlns:x="#unknown" / > Private Sub txtFirst_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub Private Sub txtSecond_LostFocus(ByVal sender As Object, ByVal e As RoutedEventArgs) e.Handled = True End Sub

          S Offline
          S Offline
          sivaddrahcir
          wrote on last edited by
          #4

          I see what you are saying about the caret staying in the TextBox that looses focus. Try setting the IsEnabled property to False and then True again after you set e.Handled = True. That seems to make the caret go away for me.

          Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com

          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