2
我的问题是,我似乎无法将选择更改事件从ComboBox编辑到TextBlock更新。所有东西都显示属性,但是当我在后面的代码中获取SelectionChanged事件中的成绩时,它不会更新实际值。要获得实际值,我必须更改ComboBox上的选择,然后单击我正在编辑的数据网格的行。然后,当我选择一个新成绩时,它会更新以显示上一次成绩选择的内容。因此,即使它看起来应该全部连接,该行实际上并没有更新,直到我点击它为止,而不是当我做出不同的ComboBox选择时。那么是否有任何方法可以改变数据网格更新数据的方式以与ComboBox保持同步?任何帮助表示赞赏。谢谢。在DataGrid中绑定TextBlock文本和组合框SelectionChanged事件
<DataGridTemplateColumn Header="Grade" CellStyle="{StaticResource StarNumberCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Grade}" Margin="3,1,3,1">
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding DataContext.Grades, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
SelectedItem="{Binding Grade,Mode=TwoWay, NotifyOnTargetUpdated=True}" Tag="{Binding}" ComboBox.IsTextSearchEnabled = "True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding DataContext.GradeSelectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
CommandParameter ="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
是啊,我有过同样的问题需要添加规范的文本框。感谢这工作。 – Kohins