I'm using the WPF XamDataGrid (v12.2) whose DataSource is bound to an ObservableCollection. I allow the user to mass edit rows via a button, so when the button is clicked I get the SelectedItems.Records, cast their DataItem to the class that they are, and then modify some of the properties. The changes do show up in the xamDataGrid, but not immediately; I either have to focus in and out of the cell that was changed, or change a column's filter, or scroll the row out and then back into view. It seems the cell's value is not updating until it is forced to.
Is there a way that I can force the changes to show up immediately? Even sending a NotifyPropertyChanged event on the ObservableCollection object that the grid is bound to does not have any effect.
Bah, I ended up wrapping my Connections class in another ConnectionsExtended class and forgot to implement INotifyPropertyChanged on the wrapper class. Everything works now after adding INotifyPropertyChanged to that class. I was even able to get rid of the ICollectionView :) Thanks!
HI,
here a link on binding to structures : http://stackoverflow.com/questions/9216353/binding-to-a-structure
Did you implement INotifyPropertyChange?
Below is what I have in my XamDataGrid (with a lot of irrelevant code removed). The ConnectionsView that I bind to is an ICollectionView, and the DatabaseConnectionStatus on the DataItem is a struct and it has a Status enumeration property. I return a Color based on the value of the Status enum value. Let me know if you need any other information. Thanks for your help :)
<igDP:XamDataGrid x:Name="grdConnectionManagerEntries" DataSource="{Binding Path=ConnectionsView, Mode=TwoWay}" IsUndoEnabled="True" ScrollingMode="Immediate" PreviewKeyDown="grdConnectionManagerEntries_PreviewKeyDown"> <igDP:XamDataGrid.Resources> ... <!-- Style to have DatabaseConnectionStatus change cell's background color, not show any text (make foreground same as background), and show an informative tooltip --> <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="DatabaseConnectionStatusToColorStyle"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="{Binding Path=DataItem.DatabaseConnectionStatus.Status, Converter={StaticResource DatabaseConnectionStatusToColorConverter}}" /> </Setter.Value> </Setter> ...
</Style> </igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="DatabaseConnectionStatus" Label="" Width="25"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource DatabaseConnectionStatusToColorStyle}" /> </igDP:Field.Settings> </igDP:Field> ...
</igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
A possible reason for the background not refreshing could be due to you binding to just the DataItem property.
You should bind to a DataItem.PropertyName ie DataItem.Status or some property inside the class represented by the DataItem.
Can you attach your CellValuePresenter Style.
I was able to fix half of my issue by using an ICollectionView in addition to my ObservableCollection, as described here.
This allowed me to call .Refresh() on my collection view to manually force the grid to refresh. This seems to refresh all of the data in the grid, except the column where I bound the background color of a cell to my DataItem property using a converter (as described here); the background color doesn't refresh until I scroll the row out of view and then back into view :(
My other option is to set the ICollectionView to null and then back to the DefaultView of my ObservableCollection, but that causes the grid to scroll back to the top left everytime the refresh is performed, so the user loses their spot in the grid.