Index IValueConverter Optimisation I've created an IValueConverter in order to Bind to the index value of a Collection.
However it seems to be rather slow/infefficient and I wonder if there is a better/different way to do this.
public class IndexValueConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        try
        {
            CollectionView collectionView = (CollectionView) parameter;
            IList collection = (IList) collectionView.ItemsSource;
        
            int convertedValue = collection.IndexOf(value) + 1;
            return convertedValue;
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
            return -1;
        }
    }
        
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

XAML
&lt;CollectionView     
    x:Name=&quot;JobPins&quot;
    ItemsSource=&quot;{Binding ACollectionView}&quot;&gt;
    &lt;CollectionView.ItemTemplate&gt;
        &lt;DataTemplate x:DataType=&quot;ADataModel&quot;&gt;
            &lt;Label
                BackgroundColor=&quot;Black&quot;
                Style=&quot;{StaticResource ListLabels}&quot;
                Text=&quot;{Binding ., 
                Converter={StaticResource IndexConverter},
                ConverterParameter={x:Reference Name=JobPins}}&quot; 
                TextColor=&quot;WhiteSmoke&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/CollectionView.ItemTemplate&gt;
&lt;/CollectionView&gt;
The best way to optimize that is store indexes directly in the source data. So, the int public Property in the ADataModel. It's rather faster to refill indexes there with O(n) complexity than with O(n2) using Converter.
The code can be a bit optimized: it's better to use bindings to pass the data to Converter. But it's not possible to pass a data to ConverterParameter using Binding. The MultiBinding+IMultiValueConverter is the solution.
&lt;CollectionView ItemsSource=&quot;{Binding ACollectionView}&quot;&gt;
    &lt;CollectionView.ItemTemplate&gt;
        &lt;DataTemplate x:DataType=&quot;{x:Type ADataModel}&quot;&gt;
            &lt;Label BackgroundColor=&quot;Black&quot; Style=&quot;{StaticResource ListLabels}&quot; TextColor=&quot;WhiteSmoke&quot; &gt;
                &lt;Label.Text&gt;
                    &lt;MultiBinding Converter=&quot;{StaticResource IndexConverter}&quot;&gt;
                        &lt;Binding Path=&quot;.&quot;/&gt;
                        &lt;Binding Path=&quot;ItemsSource&quot; RelativeSource=&quot;{RelativeSource AncestorType=CollectionView}&quot;/&gt;
                    &lt;/MultiBinding&gt;
                &lt;/Label.Text&gt;
            &lt;/Label&gt;
        &lt;/DataTemplate&gt;
    &lt;/CollectionView.ItemTemplate&gt;
&lt;/CollectionView&gt;

Alternative Binding to the Colletion as an option.
&lt;Binding Path=&quot;DataContext.ACollectionView&quot; RelativeSource=&quot;{RelativeSource AncestorType=CollectionView}&quot;/&gt;

Avoid giving names to controls where possible, it would give more flexibility for the future UI improvements.
public class IndexValueConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return values[1] is IList list ? list.IndexOf(values[0]) + 1 : -1;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException(&quot;Converting index of the List back is not supported&quot;);
    }
}

Avoid throwing Exception in converters if you don't want to crash the app. Don't build the app's logic on Exceptions in general.