Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF DataGrid
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 18-Jun-12 11:32am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.
<object UpdateSourceTrigger="UpdateSourceTrigger" .../>
 
Please refer to msdn for further info:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx[^]
  Permalink  
Comments
Clifford Nelson at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This works 100%
 
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a814c74f-6fa0-48f7-a790-8e753da422a8
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 258
2 ChintanShukla 195
3 Bhavik_Patel 170
4 Richard Deeming 165
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100