DCSIMG
Silverlight toolkit’s AutoCompleteBox and the BIDI TextBox - Ido Flatow's Blog Veni Vidi Scripsi

Ido Flatow's Blog

Veni Vidi Scripsi

News

Have you heard me speak?
Powered
<style type='text/css' media='screen' id='sm_css'> #smix {overflow: visible;height: auto;border-radius: 10px;max-width: 250px;background-color: #323232;text-align: left;font-size: 12px;line-height: 16px;font-family:'Lucida Sans Unicode','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;} #smix a {color: #0056CC;text-decoration: none;} #smix .sm_head {color: #fff; line-height: 1em;font-size: 1.4em;padding: 10px;color: #fff;} #smix .sm_lanyard_wrapper {background-color: #fff;;clear: both;width: 97%;margin: 0 auto;margin-bottom: 0px;} #smix .sm_lanyard_content {padding: 7px;}#smix button.sm_rec, #smix a.sm_rec, #smix input[type=submit].sm_rec { padding: 6px 10px; -webkit-border-radius: 2px 2px;-moz-border-radius: 2px; border-radius: 2px; border: solid 1px rgb(153, 153, 153); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 255, 255)), to(rgb(221, 221, 221))); color: #333; text-decoration: none; cursor: pointer; display: inline-block; text-align: center; text-shadow: 0px 1px 1px rgba(255,255,255,1); line-height: 1; }#smix .sm_rec:hover { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(248, 248, 248)), to(rgb(221, 221, 221))); }#smix .sm_rec:active { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(204, 204, 204)), to(rgb(221, 221, 221))); }#smix .sm_rec.medium { padding: 3px 7px; font-size: 13px; }#smix .sm_rec span.icon.thumbs_up {background-position: 0px 36px;vertical-align: text-top;display: inline-block;margin-right: 4px;height: 18px;width: 16px;background-image: url(http://speakermix.com/images/new/thumbsold.png);}#smix .sm_rec:hover span.icon.thumbs_up {background-position: 0px 18px;} #smix .sm_events {padding:2px 0px 4px 0px;} #smix .sm_section {font-size: 10px; border-bottom: 1px solid silver; margin-bottom: 6px;} #smix .sm_subline {font-size:120%;margin-top:4px;font-weight:bold} #smix .powered {text-align: right} #smix .powered img {margin: 7px} </style>
Sela Technology Center

Advertisement

Silverlight toolkit’s AutoCompleteBox and the BIDI TextBox

First of all, it as good time as any to remind everyone that Microsoft’s Silverlight 2.0 doesn’t support Right-To-Left (RTL) text writing. God knows why a solution that exists for over 15 years (the logical-visual solution for RTL languages) couldn’t be introduced into Silverlight, and as far as I know it’s not even planned for version 3.0 of SL, so all of you who are planning on writing applications in hebrew/arabic/… – beware !

There is a semi-solution today that supports RTL languages, why “Semi” you ask? Because unfortunately the control that supports RTL writing is a new control that encapsulates a text box and not a text box that was inherited to add support for RTL (By “support” I mean the visual-logical algorithm that MS overlooked) .

Why is that a problem you might ask? because some 3rd party controls have a TextBox as part of their template (for example, the AutoCompleteBox), and since the Bidi.TextBox is not of the same inheritance tree as the silverlight’s TextBox, it just doesn’t work.

What can we do about it? sometimes we can do a workaround for this problem:

1. Create a new duplicated template for the 3rd party control (oh glorious Blend).

2. Add a Bidi.TextBox control to your template

3. Hide the template’s textbox by setting it’s height to zero (You can try setting the visibility to collapsed, but I’ve noticed I didn’t get event thrown this way)

4. Apply Alex’s solution to binding of control properties and attach both Text properties (MS’s and Bidi’s)

5. Hope it work’s pretty enough…

Why isn’t it 100% proof? Because the 3rd party control might still set different properties of the original text box, such as foreground, background, selection etc., causing the Bidi.TextBox not to show all the effects you hoped to get by using the 3rd party control.

How does this relate to the SL Toolkit’s AutoCompleteBox – I’ve applied the above changes to the template and it worked, except for the problems mentioned above (you can see it when setting the IsTextCompletionEnabled property).

I myself am going to look for another autocomplete text box. If anyone has recommendations for an open-source control, I’d be happy to check it out.

 

P.S., I’ll be attending the Dev Academy tomorrow and I’ll be happy to share my experience in developing Hebrew LOB applications with SL 2. In case you don’t know what I look like -  This is me.

Comments

Justin-Josef Angel [MVP] said:

Hi Ido,

I completely disagree with your end conclusion.

As the original creator of the Silverlight 1.1 Hebrew and Arabic Languages project and as the Program Manager for the Silverlight Toolkit team - I just have more context than you on this one.

Retemplating controls is something very common in Silverlight and WPF. If you've really worked on Silverlight or WPF in real world projects you'd know that.

If you're affraid of retemplating Silverlight & WPF controls - get over it.

The fact that the Silverlight Toolkit AutoCompleteBox has such a high level of customization that you can just swap out the TextBox and ListBox with BiDi supported controls - is just plain amazing.

Not using a Silverlight Toolkit control because it doesn't support something that the rest of the Silverlight framework doesn't support is just the wrong conclusion.

The Microsoft Silverlight Toolkit has the highest standards of quality for Silverlight controls and the only reason you can retemplate it with 3rd party extensions is due to that.

Just my 0.02#, but as I've said - I've got more context around this than you do.

# December 14, 2008 4:57 AM

Ido Flatow said:

Hi Justin,

Usually I don't tend to respond to arrogant comments, but since I respect you professionaly I won't mind responding to what you mentioned.

Retemplating controls is a common thing we do as part of right-aligning different controls, but unfortunatelly basic retemplating won't work when the control's inner-code expects a different type of control in the template and therefore won't work (and indeed the toolkit is written well, thus not causing the code to crash when we supply a ListBox when a TextBox is required for instance).

Retemplating control's to support that kind of BiDi support, using the sample I gave in the post, is sometimes possible but nevertheless tedious and quite often causes me to wonder what would have happened if I was in close proximity to one of the architects in the silverlight team and had access to a shotgun that moment...

As for the toolkit - I didn't say I won't use ALL of it, I stated I'm considering other controls instead of the AutoCompleteBox, that is since I've found some other issues (bugs) with the AutoCompleteBox that prevent me from using it as I want to (already added to the issues in the codeplex site). Bugs aside, the toolkit does hold a handy set of controls and I'm sure I'll use a couple of them in the future.

To conclude, I'd accept any comment and criticism, but public arrogance is just beneath you, you know the phrase "חבל..."

# December 14, 2008 6:15 AM

Justin-Josef Angel [MVP] said:

Hi Ido,

Excellent comment, thanks for clarifying those points.

I've got nothing but professional respect for you too, but that blog post was very obscure and you got push back for that.

So what I'm hearing from you and wasn't in your original blog post is:

1. AutoCompleteBox takes a hard dependency on TextBox. I think we can solve that by changing the hard dependency from TextBox to TextBoxBase, and having SilverlightRTL's Bidi.TextBox inherit from TextBoxBase. Since SilverlightRTL is an opensource project I invite you to change the inheritance yourself and submit a fix. (ping tamir before you get started though)

2. AutoCompleteBox has bugs which are being fixed.

So, instead of saying "templating is hard" :) you might have said those 2 things, open up codeplex issues and send people to vote on them.

The entire Silverlight Toolkit team looks over the codeplex issues once a day and if we have high voted issues we'll do our best to accommodate them.

Point is - if you have community traction behind your codeplex issues we'll work on them.

-- Justin

(Use your blogging power to help solve problems, not just להתלונן :) )

# December 14, 2008 9:20 PM

Ido Flatow said:

Hi Justin,

I've been trying to "tweek" the BiDi.TextBox to do what you've talked about, but there are a couple of problems:

1. In SL, the TextBox doesn't inherit from TextBoxBase (as it is in WPF). unfortunatelly, both TextBox and TextBlock in SL inherit from Contro, so unless there is a plan to change the inheritance tree of these two classes, what you suggest cannot be done (perhaps this is why you haven't inherited this way in SilverlightRTL).

2. I've downloaded to source of the BiDi and checked if the code can be changed to inherit from TextBox, and after a days work came to the conclusion that because of the way the code manipulates the Text property of the control and the way TextBox and TextBlock displays that text makes it almost impossible to inherit the TextBox and maintaining the original Text property "unharmed".

I have managed to inherit from the TextBox and allow all the behavior of the base TextBox, but only by adding a new property ("RtlText"), but unfortunatelly because most codes the depend on the class TextBox, also use the Text property hard-coded in their code, and since there is no way currently to override properties, I just can't see a way to do anything else than what you did in your implementation.

But, on the good side, I have managed to use the BiDi control with the AutoCompleteBox (according to the workaround I've mentioned in the post) and I have managed to workaround the bug that I mentioned about the AutoCompleteBox itself (I'm still trying to understand how what I did fixed the bug, as soon as it makes sense, I'll write something about it).

If I'll have a better idea about the implementation of the SilverlightRTL, I'll be sure to post a comment in codeplex.

Ido.

# December 15, 2008 2:50 AM

Maxim said:

# December 15, 2008 2:40 PM

Justin-Josef Angel [MVP] said:

Hey, Let's pick this up via mail.

ping me at J@JustinAngel.Net.

# December 17, 2008 3:45 PM