How to ignore case when using TextBox to filter listview

Apptacular Apps 386 Reputation points
2020-06-06T11:35:13.983+00:00

Is there way of modifying the TextChanged event for a TextBox to ignore the case that has been entered? Currently in my ListView (containing town names) with a TextBox I want to search for any town name I want without having to use capital letters.

        private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtSearch.Text))
            {
                this.ListTowns.ItemsSource = this.listItemTowns;
            }
            this.ListTowns.ItemsSource = this.listTowns.Where((item) => { return item.TownTitle.Contains(txtSearch.Text); });
        }
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Matt Lacey 791 Reputation points MVP
    2020-06-06T12:14:12.787+00:00

    call .Contains(txtSearch.Text, StringComaprison.InvariantCultureIgnoreCase)

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.