Windows Presentation Foundation

Windows Presentation Foundation

Implement IViewFor<T> by hand and ensure that ViewModel is a DependencyProperty. Also, always dispose bindings via WhenActivated, or else the bindings leak memory. The XAML DependencyProperty system causes memory leaks if you don't use WhenActivated. There's a few rules, but the number one rule is: if you do a WhenAny on anything other than this, then you need to put it inside a WhenActivated. See WhenActivated for details.

The goal in this example is to two-way bind TheText property of the ViewModel to the TextBox and one-way bind TheText property to the TextBlock, so the TextBlock updates when the user types text into the TextBox.