【发布时间】:2015-03-04 16:14:38
【问题描述】:
我正在使用 Galasoft 进行 WPF 数据网格和 MVVM 设计。几列是可编辑的,我需要在单元格编辑期间执行数据库调用。
我正在尝试在单元格编辑期间捕获事件。我可以使用 Galsoft 中的 EventToCommand 选项来做到这一点。但是 EventToCommand 在网格级别应用,并且每个单元格单击事件都会触发该事件。我不想发生这种情况。
<DataGrid Grid.Column="0" Grid.Row="1" CanUserResizeRows="False" AutoGenerateColumns="False" x:Name="AdvisorDataGrid" HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="False" RowHeaderWidth="0"
Background="White" CanUserSortColumns="True" GridLinesVisibility="All" IsTabStop="False"
ItemsSource="{Binding MemberAdvisorsList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}"
IsEnabled="{Binding IsGridAdvisorsEnabled}" CanUserAddRows="True" EnableRowVirtualization="True"
CurrentCellChanged="DataGrid_CurrentCellChanged" SelectedItem="{Binding SelectedMemberDetails,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="OnFocus">
<cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding NavigateToArticleCommand,Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
另外,为了防止每个单元格事件,我将 EventToCommand 移动到列级别,但随后事件没有被触发。
无论如何,我可以这样做吗?另外,捕获单元格编辑完成操作的最佳事件名称是什么?我目前正在使用 LostFocus,但即使我第一次点击它也会被触发。
非常感谢任何帮助。
谢谢
【问题讨论】:
-
CellEditEnding 事件将在您完成编辑单元格时触发。
-
如果你想执行数据库调用,你可以使用 PreparingCellForEdit 事件。它会在单元格处于编辑模式之前触发
-
谢谢!!但是如何使用 Galasoft 在 MVVM 架构中处理 CellEditing。
-
不确定 Galasoft。在这里查看我的答案 - stackoverflow.com/questions/10680222/…
标签: wpf mvvm-light wpfdatagrid