How to set the SelectedIndex without animation?

I have a scenario where by the ItemsSource (which is bound) changes, but I need the selected item to stay the same.

In the case where the SelectedIndex == 2, if the ItemsSource has the first item removed, then SelectedIndex should be adjusted to 1, to retain the same selection.
In doing this, the SfRotator animates the same element on to the screen again.

I need the rotator, to either not animate the transition to the same element, or just understand that the net effect of the change is no change.

See attached video.

See attached sample application (click the button "Remove First Item", and watch the animation, even though the selected item did not change).

Attachment: RotatorVideoAndSampleCode_56e54cf0.zip

10 Replies

SP Sakthivel Palaniyappan Syncfusion Team March 19, 2020 02:31 PM UTC

Hi Adam,

Greetings from Syncfusion.

Query 1 : not animate the transition to the same element
We have checked the reported issue and we could able to reproduce the reported issue. In our source, we have set selected index to zero when SelectedIndex is greater than item count. So that rotator item will be animated when setting the same selected index. We have considered this as improvement in our rotator and it can track through our feedback portal below.

https://www.syncfusion.com/feedback/12859

We will include this improvement in our upcoming weekly NuGet release, which will be available on April 1st week.

Query 2 : Removing the item, selected item did not change
We noticed that in sample used List<RotatotModel> , so that view was not updated when removing item from collection. We suggest you to use ObservableCOllection<RotatotModel> instead of List<RotatotModel>   for updating view.

We appreciate your patience until then.

Regards,
Sakthivel P. 



AD Adam March 19, 2020 06:33 PM UTC

Hi Sakthivel,

I think you have not understood the bug report.

There was only 1 Query - not 2 as per your answer.

Please re-read my explanation of the problem.

Example:

ObservableCollection contains 5 items, "a", "b", "c", "d", "e".
SelectedIndex is 1
Label text is bound to element at SelectedIndex, so, it shows "b"
Remove item 0, so ObservableCollection is now, "b", "c", "d", "e"
SelectedIndex is still 1
Label text is bound to element at SelectedIndex, so, it now shows "c"
This is not desirable, so change SelectedIndex = SelectedIndex - 1
SelectedIndex is now 0
Label text is bound to element at SelectedIndex, so, it now shows "b"
This is desirable, BUT rotator will animate to position. This looks strange to user, because item animates from "b" to "b" (see video).

Solution would be to add a method "SetSelectedIndex(int index, bool animate)"

I also tried BatchBegin/BatchEnd around the changes to the collection and selected item, but it did not help.

Note: The link https://www.syncfusion.com/feedback/12859 does not work for me. I see "Access Denied". I am logged in.


SP Sakthivel Palaniyappan Syncfusion Team March 20, 2020 01:46 PM UTC

Hi Adam,

Sorry for inconvenience caused.

We have analyzed your query and we would like to inform that , if you are changing the selected index from 1 to 0 to display the same item ‘b’ after removing the item ‘a’ means animation will take since the selected index has changed from 1 to 0. As we said earlier, we have already considered this as an improvement in our SfRotator control to resolve the reported issue and it will be included in our upcoming weekly NuGet releases which will be available on April 1st,  week 2020.We appreciate your patience until then.

Can you please let us know if you are able to view or access the feedback link or not?

https://www.syncfusion.com/feedback/12859

Regards,
Sakthivel P.
 



AD Adam March 21, 2020 01:21 AM UTC

Thank you Sakthivel - yes the link works for me now.


DV Divya Venkatesan Syncfusion Team March 23, 2020 06:50 AM UTC

Hi Adam, 
 
Thanks for the update. 
 
As promised, we will include the improvement in our upcoming weekly NuGet release which will be available on April 1st week, 2020. 
 
Regards, 
Divya Venkatesan 



AD Adam April 4, 2020 02:57 AM UTC

Hi Divya,

I have upgrade to 18.1.0.42, and this bug still remains. Was it included in the release as you mentioned (April 1st week, 2020)?

Thanks


SP Sakthivel Palaniyappan Syncfusion Team April 6, 2020 12:03 PM UTC

Hi Adam,

Sorry for the inconvenience.

Due to some complexity of the issue we could not include the fix in our Weekly NuGet. We will include the fix in our upcoming weekly NuGet, which will be available on April 14th , 2020.

Regards,
Sakthivel P.
 



SP Sakthivel Palaniyappan Syncfusion Team April 15, 2020 06:48 AM UTC

Hi Adam,

We are glad to announce that our weekly NuGet was rolled out today and fix for the reported issue was included in the weekly NuGet.

NuGet Version: 18.1.0.44

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Regards,
Sakthivel P.
 



AD Adam April 15, 2020 09:36 PM UTC

Hi there,

Thanks for the notification.
I have downloaded 18.1.0.44 however, and the problem still exists.

Do I need to use any special code to add an item to the collection before the currently selected index, without causing an animation?

You see the bug still happens (new video).

To explain the video - when I pin or unpin (the red pin icon) an item, it adds or removes it from the SfRotator in the same order it appears in the list.

Is it possible the code did not make it in to the binary? I see the release notes say there were no changes...

Attachment: SfRotatorBug.mp4_e58754ba.zip


SP Sakthivel Palaniyappan Syncfusion Team April 16, 2020 02:47 PM UTC

Hi Adam,

Sorry for the inconvenience caused.

We have fixed the reported issue “When setting  SelectedIndex value as previous SelecetdIndex” in our weekly nuget (18.1.0.44)  and we will update the release notes based on this. We would like to inform that you  don't need to set the  SelectedIndex manually in your sample after updating the nuget version (18.1.0.44) .Please refer the below code snippet  for this.

C#:
 
     void Button_Clicked(System.Object sender, System.EventArgs e) 
        { 
            var oldIndex = sfRotator.SelectedIndex; 
            (sfRotator.ItemsSource as IList).RemoveAt(0); 
 
 
            sfRotator.SelectedIndex = oldIndex - 1; //Remove this code from your sample 
        } 

We have modified your provided sample based on this. Please find the sample from below location.

Sample link:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Rotator1296604915.zip

Please let us know if you have any concern.

Regards,
 
Sakthivel P. 


Loader.
Up arrow icon