【发布时间】:2020-12-22 20:09:53
【问题描述】:
<ItemsControl ItemsSource="{Binding DataViews}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<DataGrid MaxHeight="500" VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" Margin="0,0,10,0" MaxColumnWidth="450"
RowStyle="{StaticResource DataGridRowSql}" Style="{StaticResource DataGridStyleSQL}"
ColumnHeaderStyle="{StaticResource StyleDataGridColumnHeaderDefault}" ItemsSource="{Binding}"
IsReadOnly="{Binding RelativeSource={RelativeSource AncestorType=Page},Path=Locked}"
RowEditEnding="DataGrid_RowEditEnding" >
<DataGrid.CommandBindings>
<CommandBinding Command="Copy" Executed="CommandBinding_Executed"></CommandBinding>
</DataGrid.CommandBindings>
<DataGrid.InputBindings>
<KeyBinding Key="C" Modifiers="Ctrl" Command="Copy"></KeyBinding>
</DataGrid.InputBindings>
</DataGrid>
<GridSplitter Background="Red" Height="10" HorizontalAlignment="Stretch" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext"></GridSplitter>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel VerticalAlignment="Stretch"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
嗨,我需要在DataGrid_RowEditEnding 事件中更新数据,因为e.Row 没有更新数据,所以我想添加<ItemsControl ItemsSource = "{Binding DataViews, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged}" > 但它不起作用,我在哪里错了吗?
【问题讨论】:
-
如果您在数据直接输入数据网格时尝试验证数据,您会发现大量边缘情况。我通常的做法是使数据网格成为只读,用户在不同的面板覆盖中编辑所选项目。
-
不幸的是它是从数据库查询派生的数据网格,我必须通过数据网格
-
你应该检查this question,因为它似乎是你要找的。span>