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

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

7 Replies

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

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 05:33 AM

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 05:45 AM

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 08:22 AM

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 06:25 AM

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 09:52 AM

Thank you very much! Works perfect :)


HM Hemalatha Marikumar Syncfusion Team November 26, 2019 11:22 PM

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. 


Loader.
Live Chat Icon For mobile
Up arrow icon