【发布时间】:2015-03-28 16:13:50
【问题描述】:
我有一个包含 2 个 DataGrids 的窗口。如果我从第一个 DataGrid 中的一个特定列单击另一个 DataGrid 的任何列,则会出现错误
在 AddNew 或 EditItem 事务期间不允许 DeferRefresh
这里出了什么问题?
第一个DataGrid是
<DataGrid x:Name="FirstDataGrid"
ItemsSource="{Binding Parts, Mode=TwoWay}"
SelectedItem="{Binding SelectedPart, Mode=TwoWay}"
CellEditEnding="DataGrid_OnCellEditEnding" >
<i:Interaction.Behaviors>
<views:ScrollIntoViewBehavior />
</i:Interaction.Behaviors>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Identifications, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Margin="5,0,0,0">
<Hyperlink NavigateUri="{Binding ArticleNumber, Mode=OneWay}"
Command="{Binding ElementName=PartDataGrid, Path=DataContext.OpenIdentificationCommand}" CommandParameter="{Binding}" >
<TextBlock Text="{Binding ArticleNumber, Mode=OneWay}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
第二个 DataGrid 无关紧要,因为我可以单击任何列来产生错误。
【问题讨论】:
-
有趣的是,您不能重复标记赏金问题!这似乎已经在这里问过:stackoverflow.com/questions/18281615/…,在这里:stackoverflow.com/questions/20204592/…。
-
我阅读了这些,但这并没有解决我的问题。
-
从这些帖子看来,当您单击其列时,您的第一个 Datagrid 可能已进入编辑状态。您能否将属性绑定到其 SelectedItem 并(来自上面的第二个链接)“将所选项目转换为 IEditableObject 并在其上调用 EndEdit,或调用网格 CancelEdit 方法”。要么将命令连接到第一个 DataGrid 的 LostFocus 事件,以取消或提交任何待处理的编辑。