开发者

Filtering on PagedCollectionView causes problems in combination with DataForm

I am developing a Silverlight application which contains a page that looks like this:

    --------------------------------
    |          |                   |
    | DataGrid:| DataForm:         |
    |  list of |  selected         |
    |  objects |  object's details |
    |          |                   |
    --------------------------------

The user selects an object from the DataGrid and that object's details are displayed and can be edited in the DataForm on the right side.

Both the DataGrid and the DataForm bind to the same PagedCollectionView.

If I don't apply a Filter to this PagedCollectionView, everything is fine. However, when I apply a filter and then try 开发者_开发知识库to edit and save an object's details, a NullReferenceException occurs somewhere in the RaisePropertyChanged function that fires the PropertyChanged event of the object that is being edited. This exception originates from DataForm.OnCurrentItemPropertyChanged and is caused by the fact that the DataForm's CurrentItem is suddenly null.

What causes this bug, and how can I avoid it?

UPDATE: a workaround

A workaround to avoid this issue: in the object that is being edited, instead of calling RaisePropertyChanged immediately when a property's value is changed, I call this method with a delay of 100ms. This way, the DataForm and PCV can work their magic and only after they have finished, the RaisePropertyChanged calls are executed.

This probably somehow prevents some timing / synchronisation issues between the PCV the DataForm, and the object that is being edited, but I feel dirty for even typing this workaround :) Can anybody use this information to figure out what is the problem?

XAML

<controls:DataGrid 
    ItemsSource="{Binding ObjectsPCV}" 
    AutoGenerateColumns="False"
    IsReadOnly="True">

<controls:DataForm 
    ItemsSource="{Binding ObjectsPCV}" 
    AutoGenerateFields="False" 
    AutoEdit="False" 
    AutoCommit="False"
    CommandButtonsVisibility="Add, Edit, Navigation, Commit, Cancel">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜