0

so Ive got an DataGrid and in that i got a DataGridTemplateColumn. In that template Column i placed an ComboBox in it. The ComboBox got his Data from my ObservableCollections from my ViewModel. So that my Code look like that now:

 <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>

But what I want to do now is, to have an Event what triggering when I leave the ComboBox. Something like the DataGrid event CellEditEnding.

What I already tried is in my MVVM this:

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");
            }
        };

But there only the Remove Action triggerd.

I can not write in the ComboBox, I can only choose the Items that are in the ComboBox. So how can I give out an MessageBox when I'm leaving the ComboBox? So that when I click out of the ComboBox an MessageBox is triggering.

1 Answers1

0

I think you want PreviewLostKeyboardFocus or LostKeyboardFocus, So here check Detect when a ListBoxItem is in the SelectedUnfocused state and WPF Combobox lostfocus event become an Infinite lopp

CorrM
  • 498
  • 6
  • 18