Quick WPF Tip: Change as you type in WPF when binded to the same DependencyProperty
Let’s write this simple code:
<TextBox Name="source"/>
<TextBlock Text="{Binding ElementName=source, Path=Text}"/>
Now, the value of TextBlock will be changed during typing in TextBlock. However, let bind both to some DependencyProperty
<TextBox Text="{Binding Path=SomeProp}"/>
<TextBlock Text="{Binding Path=SomeProp}"/>
Now, TextBlock will be updated only when you leave TextBox. Why this happens? It’s because by default UpdateSourceTrigger property of Binding set to LostFocus, when binded to DepndencyObject.
So, how to fix it? Simple set UpdateSourceTrigger explicitly.
<TextBox Text="{Binding Path=SomeProp, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{Binding Path=SomeProp, UpdateSourceTrigger=PropertyChanged}"/>
Hurah, the value of the TextBlock (as well as the value of underlying dependency property) changing while typing into TextBox.
Have a nice day.
You may also be interested with:
- Quick IT tip: How to build bootable USB stick
- Real singleton approach in WPF application
- INotifyPropertyChanged auto wiring or how to get rid of redundant code
April 13th, 2008 · Comments (2)
2 Responses to “Quick WPF Tip: Change as you type in WPF when binded to the same DependencyProperty”
Leave a Reply
Discover other tags
My tools
- .NET Framework Detector
- Duplicate images finder
- Exchange Security Policy for Windows Mobile Devices Fix
- Gas Price Windows Vista SideBar gadget
- Israel Traffic Information Windows Vista SideBar gadget
- Localization fix for SAP ES Explorer for Visual Studio
- LocTester
- RTL and LTR in Windows Live Writer
- Silverlight controls library
- Snipping tool integration plugin for WLW
- USB FM receiver library
- Vista Battery Saver
- WebCam control for WPF
- Windows Live SkyDrive attachment for Windows Live Writer
- Wireless Migrator
- WPF Virtual Keyboard




January 1st, 2009 at 12:44 am
Thanks !
January 1st, 2009 at 12:44 am
tests time mashine