#22246·Avalonia

Autocomplete box not committing selected item from drop down

Author: kduraneCreated Sep 16, 2026Updated Sep 17, 2026
Labelsbug

Describe the bug

#21749 fixed the dropdown not closing on lost focus, but I think it may have skipped the commit the selected item from the dropdown also. This is pretty specific, but I may also be doing it wrong or not as intended. It previously worked fine though.

To Reproduce

heres my setup:

xml
<AutoCompleteBox
IsTextCompletionEnabled="False"
IsVisible="{Binding $parent[UserControl].((vm:ItemMasterBomViewModel)DataContext).ItemEnabled, Mode=TwoWay}"
ItemsSource="{Binding $parent[UserControl].((vm:ItemMasterBomViewModel)DataContext).Products}"
SelectedItem="{Binding SelectedProduct}"
Text="{Binding Ccode, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
ValueMemberBinding="{Binding Pcode, x:DataType=models:ItemMasterModel}">
   <AutoCompleteBox.ItemTemplate>
       <DataTemplate x:DataType="models:ItemMasterModel">
         <StackPanel Orientation="Horizontal" Spacing="8">
           <TextBlock
              Width="120"
              FontSize="12"
              Text="{Binding Pcode}" />
         <TextBlock
           Width="300"
           FontSize="12"
           Text="{Binding Description}" />
      </StackPanel>
    </DataTemplate>
   </AutoCompleteBox.ItemTemplate>
  <Interaction.Behaviors>
    <EventTrigger EventName="LostFocus">
       <InvokeCommandAction Command="{Binding $parent[UserControl].((vm:ItemMasterBomViewModel)DataContext).BomLineCommand}" CommandParameter="{Binding}" />
    </EventTrigger>
 </Interaction.Behaviors>
</AutoCompleteBox>

The aim of my control is to give users the chance to type a product code. for example, typing 400021 brings up a list of 2 items, 400021 and 400021EC. if you click 400021EC it isn't committed to selecteditem. The interaction command, takes the Ccode property to then fill out the rest of the form, however 400021 is sent. If you key the keyboard arrows to go down the the dropdown and select the item, that works to commit it. if you go back into the autocomplete box after the mouse click has selected the item you want, then press tab, that also commits it correctly

Expected behavior

Commit the selected item on lost focus/ dropdown closed or item selected

Avalonia version

12.1.2

OS

Linux, Windows, macOS

Additional context

No response