【发布时间】:2021-11-25 21:55:24
【问题描述】:
在 WPF 中,我有一个 DataGrid。我正在使用 MVVM。
<DataGrid x:Name="dataGrid" ItemsSource="{Binding DisplayedRows}"
SelectedItem="{Binding SelectedRow}" SelectionUnit="FullRow">
如果我更改行,则 SelectedRow 的设置器将按应有的方式运行。
有一个例外。
其中一列是DataGridTemplateColumn,其中包含ComboBox 和IsEditable="True"
<DataTemplate x:Key="CategoryEditingTemplate">
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type DataGrid}}, Path=DataContext.AppData.CategoryObjects}"
SelectedItem="{Binding Category, ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}"
DisplayMemberPath="FullName" IsEditable="True">
</ComboBox>
</DataTemplate>
如果我开始编辑ComboBox 的内容,然后单击另一行中的另一个可编辑ComboBox,则SelectedRow 的设置器不会运行。我可以用键盘编辑第二个ComboBox 的内容。如果我单击同一行中的另一个单元格,则系统会意识到该行已更改并且设置器启动。我希望设置器在我离开一行后立即运行。
更新 1
【问题讨论】:
标签: wpf mvvm combobox selecteditem