Click here to Skip to main content
15,890,947 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I permit only small letters in a TextBox? Pin
rajeevkuth17-Sep-11 6:59
rajeevkuth17-Sep-11 6:59 
AnswerRe: How can I permit only small letters in a TextBox? Pin
Luc Pattyn17-Sep-11 7:03
sitebuilderLuc Pattyn17-Sep-11 7:03 
GeneralRe: How can I permit only small letters in a TextBox? Pin
rajeevkuth17-Sep-11 8:08
rajeevkuth17-Sep-11 8:08 
GeneralRe: How can I permit only small letters in a TextBox? [modified] Pin
BillWoodruff17-Sep-11 7:31
professionalBillWoodruff17-Sep-11 7:31 
AnswerRe: How can I permit only small letters in a TextBox? Pin
Eddy Vluggen17-Sep-11 11:34
professionalEddy Vluggen17-Sep-11 11:34 
GeneralRe: How can I permit only small letters in a TextBox? Pin
BillWoodruff17-Sep-11 21:01
professionalBillWoodruff17-Sep-11 21:01 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Eddy Vluggen18-Sep-11 1:40
professionalEddy Vluggen18-Sep-11 1:40 
AnswerRe: How can I permit only small letters in a TextBox? Pin
Pete O'Hanlon18-Sep-11 10:24
mvePete O'Hanlon18-Sep-11 10:24 
There are actually two events that you need to hook into, and only one of them relates to previewing text input. The other event handler you need to add in takes care of the clipboard - people often forget that you need to handle the case when the user copies in values. If I were writing this code, I would create an Attached Behavior and handle the events in there, so setting up the actual class would look like this:
C#
public class SpecialTextboxCasing : Behavior<TextBox>
{
  protected override void OnAttached()
  {
    base.OnAttached();   
    AssociatedObject.PreviewTextInput += AssociatedObject_PreviewTextInput;
    DataObject.AddPastingHandler(AssociatedObject, OnClipboardPaste);
  }

  protected override void OnDetaching()
  {
    base.OnDetaching();
    AssociatedObject.PreviewTextInput -= AssociatedObject_PreviewTextInput;
    DataObject.RemovePastingHandler(AssociatedObject, OnClipboardPaste);
  }

  private void OnClipboardPaste(object sender, DataObjectPastingEventArgs dopea)
  {
    // Do something...
  }

  void AssociatedObject_PreviewTextInput(object sender, TextCompositionEventArgs e)
  {
    // Do something...
  }
}

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


AnswerRe: How can I permit only small letters in a TextBox? Pin
Jithin c raj18-Sep-11 23:02
Jithin c raj18-Sep-11 23:02 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Pete O'Hanlon18-Sep-11 23:42
mvePete O'Hanlon18-Sep-11 23:42 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Jithin c raj18-Sep-11 23:49
Jithin c raj18-Sep-11 23:49 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Pete O'Hanlon18-Sep-11 23:55
mvePete O'Hanlon18-Sep-11 23:55 
AnswerRe: How can I permit only small letters in a TextBox? Pin
pkwd19-Sep-11 0:50
pkwd19-Sep-11 0:50 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Pete O'Hanlon19-Sep-11 0:55
mvePete O'Hanlon19-Sep-11 0:55 
GeneralRe: How can I permit only small letters in a TextBox? Pin
pkwd19-Sep-11 2:58
pkwd19-Sep-11 2:58 
GeneralRe: How can I permit only small letters in a TextBox? Pin
Pete O'Hanlon19-Sep-11 3:07
mvePete O'Hanlon19-Sep-11 3:07 
AnswerRe: How can I permit only small letters in a TextBox? Pin
Ravi Bhavnani19-Sep-11 1:29
professionalRavi Bhavnani19-Sep-11 1:29 
QuestionHelp add new section to this config please Pin
mwpeck16-Sep-11 6:13
mwpeck16-Sep-11 6:13 
AnswerRe: Help add new section to this config please Pin
Geoff Williams16-Sep-11 6:48
Geoff Williams16-Sep-11 6:48 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 7:00
mwpeck16-Sep-11 7:00 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 14:52
mvePIEBALDconsult16-Sep-11 14:52 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 15:06
mwpeck16-Sep-11 15:06 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 17:21
mvePIEBALDconsult16-Sep-11 17:21 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 17:40
mwpeck16-Sep-11 17:40 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 17:52
mvePIEBALDconsult16-Sep-11 17:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.