开发者

Tablet PC/WPF textbox bug - any workarounds?

I've just logged this with Microsoft Connect, but I'm wondering whether anyone else has come across it and found a fix. Google's not showing much...

Simple repro:

  • Application has a WPF textbox with MaxLength set
  • Use the TabletPC input panel to write more text than is allowed
  • Press "insert" on the TabletPC panel and the application crashes

Beyond changing the behaviour of my application to not use MaxLength, does anyone know of a solution?

(I'll post here if Microsoft come back with any advice.)

EDI开发者_开发知识库T: Should have specified I'm running .NET 3.5 and Windows 7.


Depending on your application's architecture, if you're using MVVM, I might remove the MaxLength and then do validation in your ViewModel object to ensure the value matches the length you expect.

Otherwise I might use the Binding Validation like what is described in this article.

Not what I would call optimal in the case of something that's truly length limited like a zip code or a phone number, but it lets you internalize all the validation in one place.


I'll be honest, I've no experience with either WPF or Tablet PC interactions so I'm shooting blind here but I'll either hit the target or learn something :)

From my simplistic view point I see a number of work arounds, all involve removing the max length:

  1. On submission, truncate the string in the VM if too long
  2. On submission, alert user to truncation and present truncated string back to them in the textbox for editing
  3. Hang an event off the textbox and truncate the string "OnChange" with a label alert adjacent to the field, like a web form error.

Anyway, I hope you get some responses from some people who know what they are talking about ;)


Apparently this is fixed in .NET 4.0, but no plans for a 3.5 fix. The suggestion from MS was to handle the TextChanged event to provide MaxLength automatically (ew!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜