当我离开组合框时如何触发?



所以我有一个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>

但我现在想做的是,有一个事件什么触发当我离开组合框。类似于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");
}
};

但是只有Remove Actiontriggerd .

我不能在组合框中写入,我只能选择组合框中的项目。那么当我离开组合框的时候我怎么给出一个消息框呢?这样当我点击组合框外的时候,消息框就会被触发。

我认为你想要PreviewLostKeyboardFocusLostKeyboardFocus,这里检查检测当ListBoxItem处于SelectedUnfocused状态时和WPF组合框的lostfocus事件成为Infinite lopp

最新更新