Search code examples
xamarinxamarin.formsitemssource

CarouselView.FormsPlugin get index of specific page


I'm using Carousel View by alexrainman for creating custom wizard.

I need to get index of specific page by its type (I don't know exactly which index would that page have).

Something like this:

var indexAdvanced = MyCarouselView.GetIndex<ContentView>(typeof(AdditionalDefectParametersContentView));

but of course, this code doesn't work. While creating this question, I've got an idea with using CarouselView's ItemsSource. How to do it properly? TIA.


Solution

  • By the way, I've already found an answer. >_<

    The resulting code is:

    // My CarouselView consists of ContentViews
    _indexAdvanced = MyCarouselView.ItemsSource.Cast<ContentView>().
                     IndexOf(view => view is AdditionalDefectParametersContentView);
    

    So it works!

    Don't know what should I do: delete this question or leave? Maybe It would be useful for somebody, so I'll leave it for now.