如何在Silverlight中更新我的DataGrid。 [英] How to update my DataGrid in Silverlight.

查看:88
本文介绍了如何在Silverlight中更新我的DataGrid。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有cellEditingTemplates的DataGrid用于我的一个表,这些表在列中有一些导航属性。当我处理每个时,AutoGenerateColumns为False。所有Bindings都适用于像{Binding Path = ranking,Mode = TwoWay}这样设置的cellEditingTemplates,以便在编辑后尝试更新DG。它不会更新,除非我重新加载它。如果我尝试为这个实体创建一个包装类并向其添加INotifyPropertyChanged,那么CLR会声明它属于基类 - 我在模型中看到了它。每个属性似乎都处理这个事件,为什么它不会改变?我使用ObserableCollections(Of T)从WCF返回的ObjectSets中的ItemsSource。有任何想法吗?我在问这里之前做了一些认真的搜索,



设置数据:



I have a DataGrid with cellEditingTemplates for one of my tables that does have some Navigation properties within the columns. AutoGenerateColumns is False as I handle each one. All the Bindings are good with the cellEditingTemplates set like {Binding Path=ranks,Mode=TwoWay}, to attempt to update the DG after editing. It does not update, unless I reload it. If I try to make a wrapper class for this entity and add INotifyPropertyChanged to it the CLR states it belongs to the base class - which I see in the model. Each property seems to handle this event so why does it not change? I am using ObserableCollections(Of T) for the ItemsSource from the WCF returned ObjectSets. Any ideas? I have done some serious searches before asking here,

Setting the data:

cbShift.ItemsSource = shifts 'ObservableCollection
cbShift.SelectedValuePath = "ShiftId"





在`CellEditEnding`中设置选择 - per是从`DataGrid.SelectedItem`铸造的Entity对象 - 并且正在工作。





Setting the selection in `CellEditEnding` - per is the Entity object casted from the `DataGrid.SelectedItem` - and is working.

Dim cb = TryCast(dgStaff.CurrentColumn.GetCellContent(dgStaff.SelectedItem), ComboBox)
If Not cb Is Nothing Then
  Dim shiftId As Integer = Convert.ToInt32(cb.SelectedValue)
  per.ShiftId = shiftId
End If





我将它添加到Binding:UpdateSourceTrigger = PropertyChanged,它适用于实体的属性,但不适用于导航属性。



感谢您的帮助.. 。



I add this to the Binding: UpdateSourceTrigger=PropertyChanged and it works for the properties of the entity, but not the Navigation Properties.

Thanks for your help...

推荐答案

这是我的解决方法,因为似乎没有答案可用。



放置DataGrid在ScrollViewer中,当我在编辑后从服务器刷新数据时,DataGrid不必移回到位置0,因为它的高度设置为Auto并且在ScrollViewer中变得大小。这为用户提供了我想要的体验 - 更改对象并在DataGrid中查看更新后的更改,而无需回滚到原来的位置。
Here is my workaround, since no answers seem to be available.

Place the DataGrid in a ScrollViewer then when I refresh the data from the server after an edit the DataGrid does not have to move back to position 0, since it's Height is set to Auto and gets as big as it wants inside the ScrollViewer. This gives the user the experience I want - change objects and see the updated changes right where they are in the DataGrid without have to scroll back to where they were.


这篇关于如何在Silverlight中更新我的DataGrid。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆