We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to access item View inside SfRotator?

Hello,

Could you help me how to get access to the item View inside SfRotator. I'm trying to use MediaManager inside rotator, and it works fine on iOS, but I noticed some issues on Android (MediaManager has problem to find correct VideoView). Anyway, it seems it can be solved by attaching VideoView manually, but to do this, I need get access to the selected View. How to get it?

Thank you in advance for support.

Regards,
Radek

11 Replies

HM Hemalatha Marikumar Syncfusion Team November 21, 2019 06:53 AM UTC

Hi Radoslaw Kubas, 
  
Greetings, 
  
We have validated your query, you can achieve this by using SelectionChanged event in SfRotator using code snippet below. In the following code snippet ImageCollection as a List to bind the Rotator items and you can get the current view index from SelectionChanged event. 
  
Code snippet[C#] 
  
private void SfRotator_SelectedIndexChanged(object sender, Syncfusion.SfRotator.XForms.SelectedIndexChangedEventArgs e) 
        { 
            var selectedItem = viewModel.ImageCollection[(int)e.Index]; 
        } 
  
  
  
We have prepared a simple, download it from below link. 
  
  
Please let us know, if you have any other concerns. 
 
Regards, 
Hemalatha M. 



RK Radoslaw Kubas November 21, 2019 10:33 AM UTC

Hello,

Thank you for your answer, but unfortunately my problem is more complicated. I need access the View (not ViewModel). As I mentioned before I want to use SfRotator and MediaManager (https://github.com/Baseflow/XamarinMediaManager/) I have something like that (in real solution it is little more complicated but I tried to simplify it):

<SfRotator x:Name="Rotator"
     ItemsSource={Binding RotatorItems}
     SelectedIndexChanged="SfRotator_OnSelectedIndexChanged">

<SfRotator.ItemTemplate>
     <DataTemplate>
    
          <Grid>
               <VideoView Source={Binding VideoSource}/>
          </Grid > 
          
     </DateTemplate>
</SfRotator.ItemTemplate>

</SfRotator>

It works fine on iOS, but on Android MediaManager has problems to find correct view so I need to set in manually. It sosos to be something like that

 private void SfRotator_OnSelectedIndexChanged(object sender, SelectedIndexChangedEventArgs e)
{
     IVideoView playerView = GetPlayerView(Rotator, Rotator.SelectedIndex);
     CrossMediaManager.Current.MediaPlayer.VideoView = playerView;
}

private IVideoView GetPlayerView(SfRotator rotator, int index)
{
    throw new NotImplementedException();
}

My question is how to get access to the view collection inside Rotator, so I can find currently selected view and inside find reference to <VideoView>.

Best regards,
Radek



HM Hemalatha Marikumar Syncfusion Team November 22, 2019 10:45 AM UTC

Hi Radoslaw Kubas, 
  
We have validated your query. We would like to let you know that SfRotator items can be populate in two different ways. 
  
·       Through SfRotatorItem

 
·       Through ItemTemplate. 
  
We can achieve your requirement using SfRotatorItem. SfRotatorItem can have a ItemContent property. Get the item of current when the selection is DataSource by using below code snippet: 
 
CodeSnippet[XAML]: 
 
<sfRotator:SfRotator 
            x:Name="rotator" 
            SelectedIndexChanged="SfRotator_SelectedIndexChanged"  > 
            <sfRotator:SfRotator.DataSource> 
                <sfRotator:SfRotatorItem > 
                    <sfRotator:SfRotatorItem.ItemContent> 
                        <local:RotatorTemplateView/> 
                    </sfRotator:SfRotatorItem.ItemContent> 
                </sfRotator:SfRotatorItem> 
  
                    < ----------------------------------- > 
     </sfRotator:SfRotator.DataSource> 
  </sfRotator:SfRotator> 
 
CodeSnippet[C#]: 
 
private void SfRotator_SelectedIndexChanged(object sender, Syncfusion.SfRotator.XForms.SelectedIndexChangedEventArgs e) 
        { 
            var selectedView = rotator.DataSource[(int)e.Index].ItemContent; 
        } 
 
 
  
Please let us know, if you have any other concerns. 
 
Regards, 
Hemalatha M. 



RK Radoslaw Kubas November 22, 2019 01:22 PM UTC

Hello,

Thank you for this hint, I will check if it works for me, but also I have an additional question.

I noticed that property SfRotator.DataSource is obsolete. Is it going to be removed in future releases?

Best regards,
Radek


HM Hemalatha Marikumar Syncfusion Team November 25, 2019 11:25 AM UTC

Hi Radoslaw Kubas, 
  
Thanks for the update. 
 
Query: SfRotator.DataSource is obsolete. Is it going to be removed in future releases? 
 
Yes. It will be removed by any of our upcoming release. Since we have modified the sample by using ItemsSource property in SfRotator as per in below code snippet. 
 
CodeSnippet [C#]: 
 
            InitializeComponent(); 
            collectionOfItems = new ObservableCollection<SfRotatorItem>(); 
            collectionOfItems.Add(new SfRotatorItem() { ItemContent = new RotatorTemplateView() }); 
            …… 
            collectionOfItems.Add(new SfRotatorItem() { ItemContent = new RotatorTemplateView() }); 
            this.rotator.ItemsSource = collectionOfItems; 
 
 
Please find the code for getting the current view from SelectionChanged event as per in below 
 
CodeSnippet[C#]: 
private void SfRotator_SelectedIndexChanged(object sender, Syncfusion.SfRotator.XForms.SelectedIndexChangedEventArgs e) 
        { 
            var item = collectionOfItems[(int)e.Index]; 
            var selectedView = item.ItemContent; 
        } 
 
  
  
Please let us know if you have any other concern. 
  
Regards, 
Hemalatha M. 



RK Radoslaw Kubas November 26, 2019 02:52 PM UTC

Thank you very much! Works perfect :)


HM Hemalatha Marikumar Syncfusion Team November 27, 2019 04:22 AM UTC

Hi Radoslaw, 
 
Thanks for your update. 
 
We glad to hear that given solution works. 
 
Please let us know if you need any further assistance. 
 
Regards, 
Hemalatha M. 



HK Haresh Kalyani August 29, 2022 02:11 PM UTC

Hi,


The above example can only work with RotatorItem model.

How do we get the current visible item view if we are using ItemTemplate and DataTemplate?

We do not want to use RotatorItem model and use ItemTemplate with Binding.

And get the current visible item view on SelectionIndexChanged event.


How do we achieve that?

Regards,
Haresh



RS Ruba Shanmugam Syncfusion Team August 30, 2022 08:40 AM UTC

Hi Haresh,


Query: How do we get the currently visible item view if we are using ItemTemplate and DataTemplate?


We have validated your query and when using an ItemTemplate, we can retrieve the SelectedItem value of the view model using the SelectionChanged event. Because the ItemTemplate and ItemsSource combine at run time and we have not stored it in any collections. So it is currently not possible to obtain the visible item view using the ItemTemplate.


Please let us know if you need any other details.


Regards,

Ruba Shanmugam



HK Haresh Kalyani replied to Ruba Shanmugam October 13, 2022 11:40 AM UTC

Hi,

With your solution where we have ItemLayout directly attached with SfRotatorItem completely missing the concept of reusability.

As we are attaching Layout with SFRotatorItem, It will have memory issues if we have 1000+ scrolls, as its missing reusing concepts of native iOS CollectionView and Android recyclerView. 


Even default Xamarin Forms does not give a way to know VisibleItems (Contents).


I am still looking for a better way to do it !!!



RS Ruba Shanmugam Syncfusion Team October 17, 2022 11:48 AM UTC

Hi Haresh,


We regret to inform you that, as we previously stated, the visible item view cannot currently be obtained using the ItemTemplate, only the SelectedItem value of the view model using the SelectionChanged event.


Please let us know if you need any other details.


Regards,

Ruba Shanmugam


Loader.
Live Chat Icon For mobile
Up arrow icon