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