I've been adding search/filter functionalities in Edit Views and in two sub views, Transaction and Lease, I'd have to add some additional string properties in the Model if I want to add that functionality in the same way I did in other sub views like Plot, Space and Tenant:

in the ListBox of Lease view, I've Egypt: A/ Egypt: B and these have been converted with some IValueConverter this way in the DataTemplate:
space.SetBinding(Run.TextProperty, new Binding(nameof(Lease.SpaceId)) { Converter = App.convert.spaceId2spaceName });
tenant.SetBinding(Run.TextProperty, new Binding(nameof(Lease.TenantId)) { Converter = App.convert.tenantId2TenantName });
and similarly in the Transaction view, those values like BD: A | Receivable => Rent ... have been converted in this way:
...
var tenant = new FrameworkElementFactory(typeof(Run)) { Name = "tenant" };
...
space.SetBinding(Run.TextProperty, new Binding(nameof(Transaction.SpaceId)) { Converter = App.convert.spaceId2spaceName });
tenant.SetBinding(Run.TextProperty, new Binding(nameof(Transaction.TenantId)) { Converter = App.convert.tenantId2TenantName });
control.SetBinding(Run.TextProperty, new Binding(nameof(Transaction.ControlId)) { Converter = App.convert.controlId2ControlName });
head.SetBinding(Run.TextProperty, new Binding(nameof(Transaction.HeadId)) { Converter = App.convert.headId2headName });
isCash.SetBinding(BiState.IsTrueProperty, new Binding(nameof(Transaction.IsCash)));
amount.SetBinding(TextBlock.TextProperty, new Binding(nameof(Transaction.Amount)) { StringFormat = "N0" });
so these two views don't have string properties I could add filter on. Instead of changing Lease and Transaction models, I wanted to search the content of the ListBoxItem and hide/show based on the query string of the searchbox. I've this event and handler in the Transaction view:
search.TextChanged += onQueryChanged;
void onQueryChanged(string query) {
Debug.WriteLine(query);
foreach (Transaction item in transactions.Items) {
var listItem = (ListBoxItem)transactions.ItemContainerGenerator.ContainerFromItem(item);
var grid = listItem.ContentTemplate;
//grid.FindName("tenant", grid.VisualTree);
//listItem.Visibility = Visibility.Collapsed;
}
}
now, how to get the tenant string from the ContentTemplate and collapse ListBoxItem?

