开发者

RejectChanges() problem with RIA Services and Silverlight 4

I'm using SL4 and the version of RIA Services that was released at the same time as SL4 (mid-April 2010).

I have a datagrid that is bound to a PagedCollectionView that wraps the EntitySet returned by RIA Services, i.e. context.MyEntities. I don't allow editing directly in the grid. Instead, I have a separate "update" panel (a UserControl) with controls that link to the selected item of the grid.

After making several changes, I tried calling context.RejectChanges(). Almost everything reverted to the original state, including properties on associated entities. The problem is that I have a s开发者_高级运维et of 3 radio buttons in the "update" panel that are bound to an enumerated property on an associated entity. I use a value converter to set each button according to the value of the enumerated property. The bindings for all three radio buttons are set for TwoWay binding. For some reason, context.RejectChanges() reverts some changes to this property, but misses changes to the selected item. This happens even when I move to a different row after making the change, move back to the changed row, and then reject the changes.

(Perhaps the problem might be related to the fact that clicking on a radio button affects two bindings, the radio button that became unchecked and the radio button that became checked. Just a theory...) Here is the xaml for the radio buttons:

<StackPanel Orientation="Horizontal"> 
    <RadioButton x:Name="rbUnmodified" Content="Unmodified" Margin="3" IsChecked="{Binding ReviewStatus, Mode=TwoWay, Converter={StaticResource enumBoolConverter}, ConverterParameter=Unmodified}" /> 
    <RadioButton x:Name="rbInProgress" Content="In Progress" Margin="3" IsChecked="{Binding ReviewStatus, Mode=TwoWay, Converter={StaticResource enumBoolConverter}, ConverterParameter=InProgress}" /> 
    <RadioButton x:Name="rbResolved" Content="Resolved" Margin="3" IsChecked="{Binding ReviewStatus, Mode=TwoWay, Converter={StaticResource enumBoolConverter}, ConverterParameter=Resolved}" /> 
</StackPanel>

Inside the value converter, if the enumerated value of the bound property matches the converter parameter, the converter returns true, else it returns false.

Any ideas on how to fix this?


I was on the right track when I suspected that the problem was related to having multiple two-way bindings to the same property, but the failure was actually in the ConvertBack method of my EnumToBool value converter. (Whoops!) I needed to modify it to return DependencyProperty.UnsetValue when the value is false. Now everything works great!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜