Open programatix opened 2 weeks ago
@programatix Thank you for a report and a reproduction. I confirmed the issue.
There is a workaround: Bind the source collection to ItemsControl.ItemsSource
in addition to the ItemsSource
like this:
<dotNetKitControls:AutoCompleteComboBox
ItemsControl.ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Items}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Items}"
...(same)>
Note that AutoCompleteComboBox.ItemsSource
is defined as a different property than ItemsControl.ItemsSource
.
NotifyOnTargetUpdated=True
to SelectedValue
binding and a handler:<dotNetKitControls:AutoCompleteComboBox
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Items}"
SelectedValue="{Binding PersonId, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnTargetUpdated=True}"
Binding.TargetUpdated="AutoCompleteComboBox_TargetUpdated" ...>
private void AutoCompleteComboBox_TargetUpdated(object sender, DataTransferEventArgs e)
{
Debug.WriteLine($"TargetUpdated {sender}");
}
And then restarted the app, some logs were written to Output:
TargetUpdated DotNetKit.Windows.Controls.AutoCompleteComboBox Items.Count:0
One hypothesis is that it may be a timing issue that ComboBox's initilization happens before the AutoCompleteComboBox.ItemsSource
is propagated to ItemsControl.ItemsSource
.
When added inside a
DataGridTemplateColumn
, the existingSelectedValue
is not applied to the combobox. In the example at https://github.com/programatix/AutoCompleteComboBox.bug, each rows'PersonId
is set to 10, but the combobox in the DataGrid is empty. Setting thePersonId
cell also would not update the combobox. However, updating the combobox will update thePersonId
cell.