Thursday, July 29, 2010

Clearable TextBox Custom Control

After some comments from Laurent Bugnion, of Galasoft and MVVM Light fame, I decided to try my hand at turning this simple little Clearable TextBox into a custom control for better "Skinability".







It looks like I've got most of the functionality replicated, including adding two states to help with animations.  The states are "Normal" and "Cleared".  By default, the Cleared state will cause the clear button text to flash red briefly.  You can also now set the ClearButtonTemplate and the ClearButtonContent if you want.  In the picture you can see I've set the ClearButtonContent to Clear and used the default template.



<clr:ClearableTextBox  
    Text="{Binding SomeText, Mode=TwoWay}"
    ClearButtonContent="Clear"
    VerticalAlignment="Top"/>




I haven't tested any custom state animations, only the default ones that are included.  Feel free to let me know if you find any problems. The source and binaries are available below.



Clearable TextBox Custom Control Source



Now Playing: The Roots - Don't Say Nuthin

3 comments:

  1. Awesome! you should totally do a blog post on how to make a Usercontrol in WP7 that needs access to ISO storage:)

    ReplyDelete
  2. Hi,

    can you reattach the Sources? Looks like they are broken...

    ReplyDelete
  3. @RyanB58
    Do you have an example of a control that would rely on ISO Storage? Maybe a cached item list or something?
    I've got a little helper class that I use to wrap the ISO Storage functionality and treat it like AppSettings. Maybe I'll put together a post on that soon.

    @anon
    The sources look like they are back now, I'm not sure where they went. That MS Live thing is flaky, might need to switch over to dropbox.

    ReplyDelete