Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I would like to have the ViewModel updated immediately on change of value of a cell. Right now have to wait until focus leaves the record. Is there a XAML attribute I can set to cause immediate update?
Posted

Try to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.
XML
<object UpdateSourceTrigger="UpdateSourceTrigger" .../>


Please refer to msdn for further info:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx[^]
 
Share this answer
 
Comments
Clifford Nelson 19-Jun-12 12:15pm    
Thanks, I forgot about that. Could have been clearer on you answer. In this case the default was not lost focus, but the row looses focus. Give you a 5 anyway, especially since you were the only one able to answer the question. In this case the problem is that you restated what Microsoft has on thier site, and Microsoft has some of the worst documentation of anybody. The article you gave as a link is just so very bad. Probably would not have been accepted on CodeProject.
This works 100%

http://social.msdn.microsoft.com/Forums/en/wpf/thread/a814c74f-6fa0-48f7-a790-8e753da422a8
 
Share this answer
 
The best place to see about this problem is http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c71fe21a-6549-4dcf-aee9-43d02e73194f[^]. Here is some of the code from my solution:

<datagrid>
   <datagrid.resources>
     <style x:key="TextBlockRightAlignStyle" xmlns:x="#unknown">
            TargetType="{x:Type TextBlock}">
       <setter property="TextAlignment">
               Value="Right" />
       <setter property="Padding">
               Value="5,0" />
       <setter property="VerticalAlignment">
               Value="Center" />
     </setter></setter></setter></style>
     <style x:key="TextBoxRightAlignStyle" xmlns:x="#unknown">
            TargetType="{x:Type TextBox}">
       <setter property="TextAlignment">
               Value="Right" />
       <setter property="Background">
               Value="Transparent" />
       <setter property="Padding">
               Value="5,0" />
       <setter property="VerticalAlignment">
               Value="Center" />
     </setter></setter></setter></setter></style>
   </datagrid.resources>
     <datagrid.columns>
     <datagridtextcolumn header="Amount">
           Binding="{Binding Amount, StringFormat={}{0:#\,###},
              UpdateSourceTrigger=LostFocus}"
           ElementStyle="{StaticResource TextBlockRightAlignStyle}"
           EditingElementStyle="{StaticResource TextBoxRightAlignStyle}"
           Width="130" />
   </datagridtextcolumn></datagrid.columns>
 </datagrid>

I included the alignment stuff since somebody may find it useful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900