Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
235
Grid refresh problem on collection change
posted

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