Aswin Babu
Aswin Babu

Reputation: 1

combobox live filtering using Caliburn.micro

I have a combo box with live filtering of data (filtering happens as user enters or clears data) implemented using Caliburn.micro. Code behind seems to be working fine, in debug mode values were there as expected. But the issue is UI is blank, there is no data at all.

Used following collection:

public BindableCollection<string> FilteredItems
        {
            get => _filteredItems;
            set
            {
                _filteredItems = value;
                NotifyOfPropertyChange(() => FilteredItems);
            }
        }

for getting user input:

public string SearchText
        {
            get => _searchText;
            set
            {
                if (_searchText != value)
                {
                    _searchText = value;
                    _eventAggregator.PublishOnUIThread(_searchText);
                }
            }
        }

Filtering is called from here:

public void Handle(string searchText)
{
   FilterItems(searchText);
}

filtering method:

private void FilterItems(string searchText)
        {
            if (string.IsNullOrWhiteSpace(searchText))
            {
                FilteredItems.Clear();
                FilteredItems.AddRange(_originalItems);
            }
            else
            {
                var filtered = _originalItems
                    .Where(item => item.StartsWith(searchText, StringComparison.InvariantCultureIgnoreCase))
                    .OrderBy(item => item)
                    .ToList();

                FilteredItems.Clear();
                FilteredItems.AddRange(filtered);
                UpdatedWlanPrinterList = filtered.ToList();
            }
        }

UI binding:

ItemsSource="{Binding FilteredItems,Mode=Two-way}"

I ran the code with some breakpoints and values and event are there, only UI is missing data. Tried changing background and foreground colours. Tried implementation using INotifyproperty changed. Didn't use propertychangedbase since my main class already inherited one base class.

Upvotes: 0

Views: 73

Answers (0)

Related Questions