TextBox, IsReadOnly, Focus

When I set the IsReadOnly="True" then this text box no longer gets focus. If I want a readonly text box but with focus function as always how can I achieve that

It actually get the focus but do not show the caret.

Itzik



Answer this question

TextBox, IsReadOnly, Focus

  • Greg D Clark

    Bill Henning wrote:
    I was just about to post on this subject and found this thread. I'm running into a scenario where I'd like a TextBox to be read-only but I do want the caret to show and be allowed to move around. End users may wish to select a portion of the text and copy it to the clipboard even though it is read-only and right now that seems impossible other than via mouse use. Any chance this will be fixed in the future to work more like the WinForms textbox did


    You can get this behavior if ReadOnly = false and you intercept the key down event (i'm not sure which one is actually thrown) and not pass the keypress event on (by setting KeyDownEventArge e.Handled = true) if it isn't the arrow keys or a modifier. This will stop input but allow selection and give the user a caret.

  • xlordt

    as pointed out since its readonly - no text editing is possible and hence no caret is shown. Using selection is a good indicator that the textbox is in focus.
  • Bruce Baker

    Yes I was afraid of that.

    I will select all text.

    thanx guys


  • skuehner

    I was just about to post on this subject and found this thread. I'm running into a scenario where I'd like a TextBox to be read-only but I do want the caret to show and be allowed to move around. End users may wish to select a portion of the text and copy it to the clipboard even though it is read-only and right now that seems impossible other than via mouse use. Any chance this will be fixed in the future to work more like the WinForms textbox did

  • sql2000_2005

    Someone will correct me if I'm wrong, but I think that the caret indicates an insertion point. Since you can't modify read only text, so there is no insertion point.

    How about writing some code-behind to highlight the text when the text box gets focus

  • TextBox, IsReadOnly, Focus