Causing ListView to update entries

I have a ContentPage containing a RelativeList.
The RelativeList contains these two items.

ListView lv = new ListView(ListViewCachingStrategy.RecycleElement) { HasUnevenRows = false, SeparatorVisibility = SeparatorVisibility.None};
Slider slider_h = new Slider() { Value=1, Minimum=0, Maximum=1 } ;

The listview has

    ObservableCollection<string> entries = new ObservableCollection<string>();
    lv.ItemsSource = entries;
    lv.ItemTemplate = new DataTemplate(typeof(MyTextCell));

MyTextCell is

public class MyTextCell : ViewCell
Label label = new Label { FontSize = Global.labelfontheight, LineBreakMode=LineBreakMode.NoWrap, IsEnabled=false };
public MyTextCell()
    this.View = label;
protected override void OnBindingContextChanged()
    string s = BindingContext as string;
    if (s == null || s.Length < LogPage.scroll)
    label.Text = "";
    label.Text = s.Substring(LogPage.scroll);

As I add items to the ObservableCollection I update the slider maximum value accordingly.
When I move the slider I want the text in ListView to slide left/right matching the slider.

I tried many things to get MyTextCell to update but the only thing I had success with was this.

void ValueChanged_slider_h(object sender, ValueChangedEventArgs e)
    if (scroll != (int)e.NewValue)
    scroll = (int)e.NewValue;
    for (int i=0; i< entries.Count; ++i)
        if (entries[i].EndsWith(" "))
        entries[i]=entries[i].TrimEnd(' ');
        entries[i] += " ";
    //List<string> ss = new List<string>(entries);
    //entries = new ObservableCollection<string>(ss);
    //lv.ScrollTo(entries[1], 0, false);
    //lv.ScrollTo(entries[0], 0, false);
    //lv.ItemsSource = entries;
    //lv.ItemTemplate = new DataTemplate(typeof(MyTextCell));

It works OK but I guess it's not neat and probably hugely inefficient for more that a few entries.

What is the correct solution?

Sign In or Register to comment.