Selected Item event in AutoCompleteBox RRS feed

  • Question

  • When you enter something in the AutoCompleteBox and press the down arrow, it fires the SelectionChanged event.

    I want to allow the user to press down a couple of times and then hit enter at the one he wants...and THEN fire a "Selection" event.

    Sunday, September 26, 2010 12:41 PM

All replies

  • You can use dropdownclosed event or lost focus;

    Seletion change occues when the use selects the item in the autocomplete list

    Monday, September 27, 2010 1:15 AM
  • Now that is so strange.  Why does the DropDownClosed event fire twice every time you select an item from the list???  :p

    Monday, September 27, 2010 2:20 AM
  • with me it fires only once.

    Monday, September 27, 2010 2:56 AM
  • Can you please post the code

    it seems like you have initialized the event twice (Maybe you have not deregistered) Try to register it in the constructor or from the XAML

    Monday, September 27, 2010 3:13 AM
  • OK now I reimplemented it with a different name (deleted the first) and depending on what I type in, it actually fires in between some keystrokes.  I'll have to investigate it furthur as the problem seems to lie elsewhere. This is bizare.

    Monday, September 27, 2010 3:59 AM
  • OK ignor my last post.  That was just because the text I entered was not found and it closed the drop-down.

    What I did find interesting was that if the DropDown filtered list contains two items with the same "ValueMemberPath"...and I select it via Click, the SelectionChanged event's AddedItems[0] is the one I click.

    If I use the down arrow and hit <Enter> on the second item with the same "ValueMemberPath", the SelectedItem is the FIRST one!

    Am I missing something?


    Doe, Jane
    Doe, John

    ValueMemberPath = "LastName"

    SelectedItem using <Enter> gets the first one in list no matter which one you highlight.

    Monday, September 27, 2010 7:45 AM
  • This is a weird bug :D (This is not due to the similarity in selected item)

    I guess, you can try DropDownClosing event for time being;

    Monday, September 27, 2010 10:54 PM
  • Hi, I am also seeing the event fire twice. I made a small Silverlight Business Template project to demonstrate the problem. I added an AutoCompleteBox to the Home page. The xaml looks like this:

    <navigation:Page xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"





    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"


    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"

    Style="{StaticResource PageStyle}">

    <Grid x:Name="LayoutRoot">

    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" >

    <StackPanel x:Name="ContentStackPanel" Style="{StaticResource ContentStackPanelStyle}">


    <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"

    Text="{Binding Path=ApplicationStrings.HomePageTitle, Source={StaticResource ResourceWrapper}}"/>

    <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"

    Text="Home page content"/>

    <StackPanel Orientation="Horizontal">

    <sdk:Label Content="Test drop down: "/>

    <controlsInput:AutoCompleteBox DropDownClosed="test_DropDownClosed" x:Name="test" Width="100"/>







    The code behind looks like this:


    Imports System.Windows.Controls

    Imports System.Windows.Navigation

    ''' <summary>

    ''' Home page for the application.

    ''' </summary>

    Partial Public Class Home

    Inherits Page

    ''' <summary>

    ''' Creates a new <see cref="Home"/> instance.

    ''' </summary>

    Public Sub New()


    Me.Title = ApplicationStrings.HomePageTitle

    End Sub

    ''' <summary>

    ''' Executes when the user navigates to this page.

    ''' </summary>

    Protected Overloads Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)

    End Sub

    Private Sub ContentStackPanel_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ContentStackPanel.Loaded

    Dim itemslist As New List(Of String)






    test.ItemsSource = itemslist

    End Sub

    Private Sub test_DropDownClosed(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Boolean))

    MessageBox.Show("Drop Down Closed event occurred")

    End Sub

    End Class




    I am showing a message box on event DropDownClosed. When I start typing, the drop down appears. I arrow down then select. I see the message box come up twice because the event is firing twice. can anyone see what I am doing wrong or else help me understand what is happening




    Monday, March 7, 2011 5:19 PM
  • This is a weird bug :D (This is not due to the similarity in selected item)

    I guess, you can try DropDownClosing event for time being;

     you are right , why the didn't fixed it yet , thank you so much
    Sunday, February 26, 2017 9:20 PM