【发布时间】:2021-10-22 00:19:19
【问题描述】:
所以我得到了一个 DataGrid,其中我得到了一个 DataGridTemplateColumn。在该模板列中,我在其中放置了一个组合框。 ComboBox 从我的 ViewModel 中的 ObservableCollections 中获取了他的数据。所以我的代码现在看起来像这样:
<DataGridTemplateColumn Header="Status" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="cbStatus"
ItemsSource="{Binding Path=ocLieferumfangStati, ElementName=vmLieferumfang}"
Width="100" HorizontalAlignment="Left"
DisplayMemberPath="Beschreibung"
SelectedValue="{Binding Status}"
SelectedValuePath="Status" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
但是我现在想做的是,当我离开 ComboBox 时,有一个 Event 触发什么。类似于 DataGrid 事件 CellEditEnding。
我已经尝试过的是在我的 MVVM 中:
ocLieferumfangStati.CollectionChanged += (sender, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
MessageBox.Show("ADD");
}
if (e.Action == NotifyCollectionChangedAction.Move)
{
MessageBox.Show("Move");
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
MessageBox.Show("Remove");
}
if (e.Action == NotifyCollectionChangedAction.Replace)
{
MessageBox.Show("Replace");
}
};
但只有 删除操作 被触发。
我不能在 ComboBox 中写,我只能选择 ComboBox 中的项目。那么,当我离开 ComboBox 时,如何才能发出 MessageBox 呢?这样当我点击 ComboBox 时,就会触发 MessageBox。
【问题讨论】:
-
“离开”是指“失去焦点”? stackoverflow.com/questions/27820278/…
-
我的意思是当我点击组合框时。
-
是的,但“敲出”不是一个事件。当您执行此类操作时,会触发许多更具体的事件。
-
也许您正在寻找 SelectionChanged?