This is a migrated thread and some comments may be shown as answers.

Updating DataSource loses display of selected item

6 Answers 51 Views
LoopingList
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 14 Oct 2014, 11:22 PM
Hi,

I have run into some strange behaviour, when changing the DataSource driving the RadLoopingList.

Steps:
  1. Change the selected item to number 10 (image 1.png)
  2. Press the application bar button, which will recreate the DataSource.
  3. Observe that the LoopingList jumps to the very top, and the selected item is not visible (image 2.png).
  4. Press the application bar button.
  5. Observe the selected item jumps to the center as expected.

<telerikPrimitives:RadLoopingList
    ItemWidth="120"
    ItemHeight="120"
    Width="120"
    IsCentered="True"
    DataSource="{Binding DataSource}"
    SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"/>

public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged
{
    LoopingListDataSource dataSource;
    int selectedIndex = -1;
 
    public MainPage()
    {
        InitializeComponent();
        DataContext = this;
 
        CreateDataSource();
    }
 
    public LoopingListDataSource DataSource
    {
        get { return dataSource; }
        set { dataSource = value; NotifyPropertyChanged("DataSource"); }
    }
 
    public int SelectedIndex
    {
        get { return selectedIndex; }
        set { selectedIndex = value; NotifyPropertyChanged("SelectedIndex"); }
    }
 
    private void CreateDataSource()
    {
        DataSource = new LoopingListDataSource(1000);
 
        dataSource.ItemNeeded += (sender, args) =>
        {
            args.Item = new LoopingListDataItem();
        };
 
        dataSource.ItemUpdated += (sender, args) =>
        {
            args.Item.Text = args.Index.ToString();
        };
    }
 
    private void Button_Click(object sender, EventArgs e)
    {
        CreateDataSource();
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        if (null != PropertyChanged)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

So it seems that the problem only occurs the first time the DataSource is swapped, and only after the selected index was changed.

Any help is much appreciated in what helping resolve this problem

Thanks
Ryan

6 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 14 Oct 2014, 11:23 PM
Image attached.
0
Ryan
Top achievements
Rank 1
answered on 16 Oct 2014, 07:17 PM
Any updates on this?

I have a sample project however this forum only lets me attach pictures...
0
Dimitrina
Telerik team
answered on 17 Oct 2014, 03:19 PM
Hi Ryan,

We need some more time to further investigate it. I will write again with our findings. Please don't hesitate to contact us in  case you have any additional questions.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ryan
Top achievements
Rank 1
answered on 23 Oct 2014, 06:10 PM
Hi Dimitrina,

Let me know if there is anything else you need to help me with this problem. I have a sample project which reproduces the behaviour I can provide.

Thanks
Ryan
0
Accepted
Rosy Topchiyska
Telerik team
answered on 27 Oct 2014, 01:57 PM
Hi Ryan,

We have successfully reproduced this behavior. You will have to call the LoopingListDataSource.UpdateLayout() method when you change the DataSource:
private void CreateDataSource()
{
    this.DataSource = new LoopingListDataSource(1000);
 
    this.dataSource.ItemNeeded += (sender, args) =>
    {
        args.Item = new LoopingListDataItem();
    };
 
    this.dataSource.ItemUpdated += (sender, args) =>
    {
        args.Item.Text = args.Index.ToString();
    };
 
    this.dataSource.UpdateLayout();
}

I hope this helps and sorry for the delay. Please, do not hesitate to contact us if you have any other questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ryan
Top achievements
Rank 1
answered on 27 Oct 2014, 06:44 PM
Thanks Rosy, your work-around performs perfectly!
Tags
LoopingList
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Dimitrina
Telerik team
Rosy Topchiyska
Telerik team
Share this question
or