Posts
114
Comments
126
Trackbacks
10
December 2009 Entries
Use UpdateSourceTrigger=PropertyChanged for immediate updates of bound XAML controls

My XAML learning project is inspired by Leon Bambrick’s “World’s Simplest Code Generator” (http://secretgeek.net/wscg.htm). It’s a 3-pane window where you type or paste data into the top pane, enter a formatting pattern in the middle pane, and it displays the formatted results in the bottom pane:

Codey

(Yes, I know about auto-implemented properties, Visual Studio snippets, and T4. The property-generating scenario above is just for example purposes.)

The TextBox controls are bound to properties of my ViewModel, but by default the input and format properties are only updated (triggering an update to the results property) when the controls lose focus.

I want the results to be updated immediately as I type, so I did that by handling the TextChanged events in code-behind. I knew there was probably a way to do it without code-behind, but didn’t know how until I watched Jason Dolinger’s M-V-VM video.

I added “UpdateSourceTrigger=PropertyChanged” to the binding expressions:

    <TextBox
        DockPanel.Dock="Top"
        Text="{Binding InputText, UpdateSourceTrigger=PropertyChanged}" />

…and bada-bing, the results are now updated with each keystroke as I update the input and format, with no code-behind.

Treat code-behind like your real behind: You don’t want a lot of junk in the trunk! ;)

Posted On Saturday, December 12, 2009 8:15 AM | Comments (0)
Video: Jason Dolinger on Model-View-ViewModel (MVVM)

A very nice overview for XAML newbies in which Jason starts with a simple WPF app coded like the first attempt at a developer coming from a Windows Forms background, and step by step transforms it into into a much more manageable, encapsulated, readable, and testable M-V-VM design:

http://blog.lab49.com/archives/2650

Posted On Thursday, December 10, 2009 9:28 AM | Comments (0)
Visual Studio Shortcut for “Show Smart Tag”

I keep forgetting the keyboard shortcut for this, and can’t remember what the dang thing’s called to search for it. I’m putting it in my blog so I can find it again.

Thanks to David Morton for the nice explanation (http://blog.codinglight.com/2009/03/few-visual-studio-shortcuts.html):

Show Smart Tag - [Shift]+[Alt]+[F10] - What's a smart tag? The smart tag is that little elusive box that gives you options about how to refactor code in certain ways. It's the box that can be opened to add a using statement to the top of your code when you enter a class name that is in a namespace not already in your using statements. I've always found that opening this box can be a little elusive, as I have to hover my mouse over it just right to get the box to expand enough for me to click it. Definitely saves time.

Posted On Saturday, December 5, 2009 10:20 AM | Comments (2)
Tag Cloud