IValueConverter is called multiple times

Hi There,

I didn't found a solution on that, so i hope anyone of you could help me.
in my Project i have a ListView with DataTemplate:

string[] bla = { "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3", "h1", "h2", "h3"};
lv.ItemsSource = bla;
lv.ItemTemplate = new DataTemplate(() =>
{

            var lbl_option = new Label { FontSize = 15 };
            //var lbl_sn = new Label { FontSize = 15 };

            lbl_option.VerticalTextAlignment = TextAlignment.Center;
            //lbl_sn.VerticalTextAlignment = TextAlignment.Center;

            lbl_option.SetBinding(Label.TextProperty, new Binding(".", BindingMode.OneWay, new Conv1(), lv));
            //lbl_sn.SetBinding(Label.IsVisibleProperty, new Binding(".", BindingMode.OneWay, new LVSNVisibilityConverter(), lv));

            Grid _grid = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand };
            _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            _grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            //_grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(4, GridUnitType.Star) });

            _grid.Children.Add(lbl_option, 0, 0);
            //_grid.Children.Add(lbl_sn, 1, 0);

            return new ViewCell { View = _grid };
        });

iam trying to use a converter for getting the actual row (to show as a number):

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ConverterExampleView.row++;

        var ls = ((ListView)parameter);
        List<string> lmd = new List<string>();
        foreach (string md in ls.ItemsSource)
            lmd.Add(md);

        return "Option " + ConverterExampleView.row;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

The problem is, that the converter always is calles multiple times for one item--> if i have 10 items first item would be displayed as Option 3, the second Option 6 and so on. why three times for one item and how to make it right? (option 1, Option 2, ...)

P.S.: On my second converter for visibility 3 times isn't enough...

Hope you can help me!

Sign In or Register to comment.