Hi
I'm using XamWebGrid to display some data in a Silverlight application. One of the data is displayed in a grid as a date field. When a value changes I update the view model in a collection and reassign the collection to the grid like this:
GridItems = new ObservableCollection<DataItem>(_items);
GridItems is a property binded to grid's ItemsSource. The problem is that grid does not update, but when I do this, it works:
GridItems = null;GridItems = new ObservableCollection<DataItem>(_items);
Why is that?
Another thing I also noticed. DataItem is defined as below. Notice the private setter!
public class dataItem{ public DateTime ValidFrom { get; private set; }}
With a private setter, although grid refreshes, date values don't and they become null or something. Grid just displays "dd.mm.yyyy" with a gray text. if I use public setter instead, refreshing works.
Here is a grid definition:
<XamWebGrid Grid.Row="1" AutoGenerateColumns="false" ItemsSource="{Binding GridItems, Mode=OneWay}" behaviors:DataGridSelectedRowBehavior.SelectedItem="{Binding SelectedItem, Mode=TwoWay}"> <XamWebGrid.Columns> <DateColumn Key="ValidFrom"> <DateColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="Valid from" /> </DataTemplate> </DateColumn.HeaderTemplate> </DateColumn> </XamWebGrid.Columns></XamWebGrid>
Again, why is that? Both behaviours are very strange to me and I don't understand why.
regards
Tomaz
Hi Tomaz.
Regarding your first issue:
In the Setter of GridItems are your raising the PropertyChanged event? B/c you need to do this in order for the XamGrid to be notified that its changing.
As for your ValidFrom property, you need to raise the PropertyChanged when its updated. The fact that the setter is private doesn't matter. As long as you raise the event, the grid will update.
Hope this helps,
-SteveZ
Yes it does, but I don't call the notify method because the whole ItemsSource collection is replaced on a Grid.
Does your VM and the GridItems property implement the INotifyPropertyChanged interface?
Devin