Hello, Welcome to Micorosoft Q&A,
Search should be made by specified property.
For your scenario, I have completed code, please refer the following to filter your collection.
public class MyObservableCollection<T> : ObservableCollection<T>
{
public int Find(string propertyName, string textToFind)
{
int index = -1;
var FilteredItems = this.Where(item => GetPropertyValue(item, propertyName).ToString().IndexOf(textToFind, StringComparison.InvariantCultureIgnoreCase) >= 0);
foreach (var item in FilteredItems)
{
index = this.IndexOf(item);
}
// we suggest your return FilteredItems, or it will reture last one's index of current collection from FilteredItems
return index;
}
object GetPropertyValue(T entity, string propetyName)
{
object result = null;
Type entityType = typeof(T);
try
{
PropertyInfo proInfo = entityType.GetProperty(propetyName);
result = proInfo.GetValue(entity);
}
catch (Exception)
{
throw;
}
return result;
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.