New article on "The first rule of WPF"

3 views
Skip to first unread message

Bill Kempf

unread,
Aug 20, 2008, 12:30:36 PM8/20/08
to wpf-di...@googlegroups.com
Hopefully an interesting read.
 
http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!508.entry

--
Quidquid latine dictum sit, altum sonatur.
- Whatever is said in Latin sounds profound.

War is peace. Freedom is slavery. Bugs are features.

Corrado Cavalli

unread,
Aug 20, 2008, 12:49:57 PM8/20/08
to wpf-di...@googlegroups.com

Nice reading!

Attached behaviors rocks!

Marlon Grech

unread,
Aug 20, 2008, 3:04:52 PM8/20/08
to wpf-di...@googlegroups.com
very very nice!!!! I love it....

I will do a comment in MaskedTextbox post to link to this post!!!!!

P.S if you want to use any code from AvalonControlsLibrary just drop me an email. The code is for the community to use, no paper work needed!!!! actually I would even love if people ask me for that code so that if issues are found I can fix them and the community would benefit.....

Bill Kempf

unread,
Aug 20, 2008, 4:51:53 PM8/20/08
to wpf-di...@googlegroups.com
The paper work is on my end.  Company policy is you can't use any outside code with out it being "vetted" by legal.  Even with standard licenses that have been approved in the past, this "vetting" still has to happen.  In many cases, simply reinventing the wheel causes less friction.  Yes, this is still evil, but it's not the same evil as NIH syndrome ;).
 
Thanks for the response and praise, though.  Much appreciated.

Marlon Grech

unread,
Aug 20, 2008, 6:05:45 PM8/20/08
to wpf-di...@googlegroups.com
you're the man!

anytime you need anything let me know bro

rudigrobler

unread,
Aug 21, 2008, 2:24:50 AM8/21/08
to WPF Disciples
Great!!! I love attached behavior...

Mike Brown

unread,
Aug 21, 2008, 9:46:01 AM8/21/08
to wpf-di...@googlegroups.com
Great job Bill! I like how you point out that by using attached behaviors you could in theory adapt the behavior to support something other than a textbox.

Bill Kempf

unread,
Aug 21, 2008, 10:37:49 AM8/21/08
to wpf-di...@googlegroups.com
Thanks Mike.  I need to explore that idea further.  Low hanging fruit would probably be to get it to work with TextBoxBase, but that only gets us TextBox and RichTextBox and I'm not sure there'd be a reason to mask a RichTextBox?  After that it gets a little more complex.  Maybe I could step through TemplatePartAttribute's on the control looking to see if there's a single TextBox(Base) part, and apply the behaviors there.  Of course, I could also walk the tree looking for children of type TextBox(Base).  Doing that should cover the vast majority of the cases where this behavior would be applicable.

Bill Kempf

unread,
Aug 21, 2008, 11:09:12 AM8/21/08
to wpf-di...@googlegroups.com
Wow. I was soooo wrong. TextBoxBase isn't low hanging fruit.  Microsoft messed up the access levels once again!  One of the most fundamental concepts of any TextBox type is selection.  In fact, TextBoxBase exposes a lot of concepts based around this, like a SelectionChanged event, AutoWordSelection and Cut/Copy/Paste based on the selection.  However, there's no way to determine what the selection is!
 
TextBox and RichTextBox aren't consistent in how they expose the selection.  TextBox exposes SelectionStart and SelectionEnd while RichTextBox exposes a Selection.  That's wacky enough to be highly questionable to me.  Just bad design.  But what's worse is that all of these methods are implemented in terms of a TextSelectionInternal on the base TextBoxBase, which, like the name indicates, is internal!  How did this design pass code review?
 
There's no way to base behaviors here on TextBoxBase.  If I cared about RichTextBox I'd have to provide two separate implementations (at least partially... I can envision a few ways to hack around this in order to reuse at least some of the behavioral code).  Then again, there's other issues with masking a RichTextBox (there's no simple Text concept, for example), and I really don't care to do so, so there's not too much reason to care about this in this case.  However, that doesn't make the Selection issue on TextBoxBase any less forgivable, IMHO.

Reply all
Reply to author
Forward
0 new messages