views:

1455

answers:

2

Can someone direct me to an example or explanation that will help me either:

  1. Extend the SilverLight AutoComplete Box to allow watermarks.
  2. Extend the Watermark TextBox to allow AutoComplete functionality.

It strikes me that option 1 would be easiest, but I'm open.

Thanks in advance.

+2  A: 

Right off the bat, I'd say option 1 is good:

1) Create an attached property to hold the WatermarkText that you can use on AutoCompleteBox.

2) Create a control template for the AutoCompleteBox (simply copy the existing one using blend), but change the TextBox to a Watermark TextBox, and use a TemplateBinding to set the WatermarkTextBox's property to the value of the attached property. The control template should be applied in a style (for example WatermarkedAutoCompleteBoxStyle).

You should be good to go with that. Any time you want a watermarked autocomplete box, just set the attached property value and apply the style you defined.

If you need more in-depth explanation of one of those steps, just raise your hand and I'll try to find the time to create a sample.

Alternatively you can derive from AutoCompleteBox, add a DependencyProperty instead of an attached property and package the style in the Themes/generic.xaml file, but I usually do it once it works.

Denis Troller
LOL...OK, hand officially raised. You don't have to create an example, but if you can point to a GOOD example of #1. I haven't had to actually create an attached property yet. Thanks!
Steve Brouillard
actually I have an example of using an attached property to do something similar (not quite, but it should show you the syntax) at http://denis-troller.blogspot.com/ (it's not a plug, there's actually only that article over there :))
Denis Troller
Denis. Thanks very much. Appreciate the info.
Steve Brouillard
let me know if that's not enough for what you need
Denis Troller
A: 

That was great! How can achieve watermark visibility= "True/False" on focus event? e.g.like Search box in IE8

Abhijeet