private void ApplicationView_Search(object sender, FilterEventArgs e) { if (string.IsNullOrEmpty(SearchText)) { e.Accepted = true; return; } // Search for application name and description without "-" and " " ApplicationViewInfo info = e.Item as ApplicationViewInfo; Regex regex = new Regex(@" |-"); // Try to find the translated application view name first --> it's faster when the language ist different than english and equal when it's english if ((regex.Replace(info.TranslatedName, "").IndexOf(regex.Replace(SearchText, ""), StringComparison.OrdinalIgnoreCase) >= 0) || (regex.Replace(info.Name.ToString(), "").IndexOf(regex.Replace(SearchText, ""), StringComparison.OrdinalIgnoreCase) >= 0)) { e.Accepted = true; } else { e.Accepted = false; } }
private void LoadApplicationList() { _applications = CollectionViewSource.GetDefaultView(ApplicationViewManager.List); _applications.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); // Always have the same order, even if it is translated _applications.Filter = o => { if (string.IsNullOrEmpty(Search)) { return(true); } // Search for application name and description without "-" and " " ApplicationViewInfo info = o as ApplicationViewInfo; Regex regex = new Regex(@" |-"); string search = regex.Replace(Search, ""); // Search by TranslatedName and Name return((regex.Replace(info.TranslatedName, "").IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1) || (regex.Replace(info.Name.ToString(), "").IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)); }; SelectedApplication = Applications.SourceCollection.Cast <ApplicationViewInfo>().FirstOrDefault(x => x.Name == SettingsManager.Current.Application_DefaultApplicationViewName); }