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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to access item View inside SfRotator?

Thread ID:

Created:

Updated:

Platform:

Replies:

149295 Nov 20,2019 09:56 PM UTC Nov 27,2019 04:22 AM UTC Xamarin.Forms 7
loading
Tags: SfRotator
Radoslaw Kubas
Asked On November 20, 2019 10:51 PM UTC

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

Hemalatha Marikumar [Syncfusion]
Replied On 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. 


Radoslaw Kubas
Replied On 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


Hemalatha Marikumar [Syncfusion]
Replied On 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. 


Radoslaw Kubas
Replied On 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

Hemalatha Marikumar [Syncfusion]
Replied On 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. 


Radoslaw Kubas
Replied On November 26, 2019 02:52 PM UTC

Thank you very much! Works perfect :)

Hemalatha Marikumar [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon