Updating DataSource loses display of selected item

7 posts, 1 answers
  1. Ryan
    Ryan avatar
    21 posts
    Member since:
    Apr 2013

    Posted 14 Oct 2014 Link to this post

    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

  2. Ryan
    Ryan avatar
    21 posts
    Member since:
    Apr 2013

    Posted 14 Oct 2014 in reply to Ryan Link to this post

    Image attached.
  3. DevCraft banner
  4. Ryan
    Ryan avatar
    21 posts
    Member since:
    Apr 2013

    Posted 16 Oct 2014 in reply to Ryan Link to this post

    Any updates on this?

    I have a sample project however this forum only lets me attach pictures...
  5. Dimitrina
    Admin
    Dimitrina avatar
    442 posts

    Posted 17 Oct 2014 Link to this post

    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.

     
  6. Ryan
    Ryan avatar
    21 posts
    Member since:
    Apr 2013

    Posted 23 Oct 2014 in reply to Dimitrina Link to this post

    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
  7. Answer
    Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 27 Oct 2014 Link to this post

    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.

     
  8. Ryan
    Ryan avatar
    21 posts
    Member since:
    Apr 2013

    Posted 27 Oct 2014 in reply to Rosy Topchiyska Link to this post

    Thanks Rosy, your work-around performs perfectly!
Back to Top
DevCraft banner