The best option is to create a ValueConverter (or two value converters). You did not give enough detail to provide exactly the right answer, but here I am returning a count of where a ListBox is bound to an ItemsSource of IEnumerable<string>, and counting matches where the string is the same as the parameter:
public class CountConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var listBox = value as ListBox;
if (listBox != null)
{
var list = listBox.ItemsSource as IEnumerable<string>;
if (list != null)
return list.Count(i => i == parameter.ToString());
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}