This is a migrated thread and some comments may be shown as answers.

AutoCompleteBox loses highlighting when the item collection changes while the AutoCompleteBox is active and the popup is open.

2 Answers 15 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Pooja
Top achievements
Rank 1
Pooja asked on 14 Oct 2014, 09:07 PM
AutoCompleteBox loses its highlighting when the itemsource collection changes. To reproduce this issue type in the AutoCompleteBox and while it’s active and the popup is open, trigger a collection change event. The highlighting will automatically disappear, now if the collection changes again the highlighting reappears. This keeps toggling back and forth.

Attached is the screenshot.

Below are the code snippets.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using Telerik.Windows.Controls;
 
namespace HighlightMatchingItemsText
{
    public class Country
    {
        public string Name { get; set; }
        public string Capital { get; set; }
    }
 
    public class ViewModel : ViewModelBase
    {
        private ObservableCollection<Country> countries;
 
        public ViewModel()
        {
            this.Countries = new ObservableCollection<Country>()
            {
                new Country() { Name = "Australia", Capital = "Canberra" },
                new Country() { Name = "Bulgaria", Capital = "Sofia" },
                new Country() { Name = "Canada", Capital = "Ottawa" },
                new Country() { Name = "Denmark", Capital = "Copenhagen" },
                new Country() { Name = "France", Capital = "Paris" },
                new Country() { Name = "Germany", Capital = "Berlin" },
                new Country() { Name = "India", Capital = "New Delhi" },
                new Country() { Name = "Italy", Capital = "Rome" },
                new Country() { Name = "Norway", Capital = "Oslo" },
                new Country() { Name = "Russia", Capital = "Moscow" },
                new Country() { Name = "Spain", Capital = "Madrid" },
                new Country() { Name = "United Kingdom", Capital = "London" },
                new Country() { Name = "United States", Capital = "Washington, D.C." },
            };
 
            var o = System.Reactive.Linq.Observable.Start(() =>
            {
                //starts on a background thread.
                while (true)
                {
                    Thread.Sleep(6000);
                    this.Countries = new ObservableCollection<Country>()
                    {
                        new Country() { Name = "Australia", Capital = "Canberra" },
                        new Country() { Name = "Bulgaria", Capital = "Sofia" },
                        new Country() { Name = "Canada", Capital = "Ottawa" },
                        new Country() { Name = "Denmark", Capital = "Copenhagen" },
                    };
                    Console.WriteLine("Collection Changed");
                }
            });
 
        }
 
         public ObservableCollection<Country> Countries
        {
            get { return this.countries; }
            set
            {
                if (this.countries != value)
                {
                    this.countries = value;
                    this.OnPropertyChanged(() => this.Countries);
                }
            }
        }
    }
}

<UserControl x:Class="HighlightMatchingItemsText.Example"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:local="clr-namespace:HighlightMatchingItemsText"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300" Width="300">
    <UserControl.DataContext>
        <local:ViewModel />
    </UserControl.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Type A in the autocomplete box, Australia gets highlighted. Keep the drop down open and wait for 6 seconds, the collection changes and the highlighting dissappears.
                   Wait for another 6 seconds, the collection changes and the highlighting reappaers. This keeps toggling. "
                   TextWrapping="Wrap"
                   FontWeight="Bold"
                   Margin="20"/>
        <telerik:RadAutoCompleteBox x:Name="AutoComplete"
                                    Grid.Row="1"
                                    Margin="20"
                                    ItemsSource="{Binding Countries}"
                                    TextSearchPath="Name"
                                    TextSearchMode="Contains"
                                    AutoCompleteMode="Suggest"
                                    >
        </telerik:RadAutoCompleteBox>       
    </Grid>
</UserControl>


2 Answers, 1 is accepted

Sort by
0
Pooja
Top achievements
Rank 1
answered on 14 Oct 2014, 09:19 PM
Reposted in the 'Telerik Forums / UI for WPF Forum / AutoCompleteBox /'   forum.

http://www.telerik.com/forums/autocompletebox-loses-highlighting-when-the-item-collection-changes-while-the-autocompletebox-is-active-and-the-popup-is-open-66b627941d96#SjY82kSRz0ap4L3Y_AkZYQ
0
Vladi
Telerik team
answered on 17 Oct 2014, 10:12 AM
Hello Pooja,

Could we continue the discussion in the other thread (with ID: 869129) which you have started.

Regards,
Vladi
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
AutoCompleteBox
Asked by
Pooja
Top achievements
Rank 1
Answers by
Pooja
Top achievements
Rank 1
Vladi
Telerik team
Share this question
or