首先尝试在业务线项目上实现MVVM模式。我遇到了一些问题,我假设有这样的eaiser答案:WPF MasterDetail ViewModel延迟更新到主列表。 (防止网格自动更新)
原型窗口是项目列表的基本主从视图。 (Person对象列表)。该视图包含主列表的Infragistics xamDataGrid。由于在网格中选择了该项目,因此您可以在下面的详细信息面板中编辑详细信息,并在详细信息面板中标注字段时更新显示在网格数据中的“实时”。唯一的事情是我不想“presto”,我想要“等到我按下”Apply Changes“按钮”。
我一直希望避免创建一个单独的列表实例来从我在细节面板中添加/删除/修改的项目的工作集中分离出主列表。
我已经下降的路径:
我推翻了CellValuePresenter风格在网格领域,所以我可以设置绑定为“单向”。这阻止了实时更新。
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<ControlTemplate.Resources>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="{Binding Path=DataItem.NameUIProperty.IsDirty, Converter={StaticResource BooleanBrushConverter}}" />
<Setter Property="IsEnabled" Value="{Binding Path=DataItem.NameUIProperty.IsEditable}" />
</Style>
</ControlTemplate.Resources>
<ContentControl>
<TextBlock Text="{Binding Path=DataItem.Name, Mode=OneTime}" />
</ContentControl>
</ControlTemplate>
然后我添加一个“的ApplyUpdates”命令(RelayCommand)我PersonListViewModel。这引发了“PERSON _ITEM_
UPDATED”消息。我正在使用MVVM Foundation Messenger和RelayCommand类的VB端口。
#Region "ApplyUpdates Command"
Private mApplyUpdatesCommand As New RelayCommand(AddressOf ApplyUpdates)
Public ReadOnly Property ApplyUpdatesCommand() As ICommand
Get
Return mApplyUpdatesCommand
End Get
End Property
Private Sub ApplyUpdates()
'the changes are already in the object in the list so we don't have to do anything here except fire off the Applied message
Messages.AppMessenger.NotifyColleagues(Messages.PERSON_ITEM_UPDATED)
End Sub
#End Region
的PersonView登记该PERSON _ITEM_
更新的消息和接收到消息时重新绑定网格。
'In Loaded Event
'register for window messages we care about
Messages.AppMessenger.Register(Messages.PERSON_ITEM_UPDATED, AddressOf OnPersonItemUpdated)
'EventHandler
Private Sub OnPersonItemUpdated()
PersonGrid.DataSource = Nothing
PersonGrid.DataSource = mViewModel.List
End Sub
所以,那有效,但它smells wrong。该视图似乎有太多的逻辑,并且ViewModel没有规定UI的状态,视图是。
我错过了什么?你会用什么方法让ViewModel延迟发布视图的更改?
更新:我现在正在为网格创建自定义ViewModel的路径(只读,没有Propertychanged通知)和可编辑的ViewModel的细节区域。两个VM都会包装相同的业务对象,但ReadOnly版本不会发布更改。这会让虚拟机控制视图更新的时间。
感谢Infragistics提示。有一天这将派上用场! – TheZenker 2009-11-30 19:44:10