using System; using System.Windows.Input; using Xamarin.Forms; namespace TINK.ViewModel.Info.BikeInfo { public class CourouselPageItemViewModel { public CourouselPageItemViewModel( string p_strTitle, string p_strLegend, int p_iCurrentPageIndex, Func p_iPagesCountProvider, Action p_oCloseAction, ImageSource image = null) { Title = p_strTitle; IsImageVisble = image != null; if (IsImageVisble) { Image = image; } DescriptionText = p_strLegend; CurrentPageIndex = p_iCurrentPageIndex; PagesCountProvider = p_iPagesCountProvider; CloseAction = p_oCloseAction; } /// Gets the title of the navigation page. public string Title { get; } public bool IsImageVisble { get; } /// Gets the image. public ImageSource Image { get; } /// Gets the text which describes the image. public string DescriptionText { get; } /// Get the progress of the carousselling progress. public double ProgressValue { get { var l_oCount = PagesCountProvider(); return l_oCount > 0 ? (double)CurrentPageIndex / l_oCount : 0; } } /// Gets if user can leave carousel page. public bool IsCloseVisible { get { return PagesCountProvider() == CurrentPageIndex; } } /// Command object to bind close button to view model. public ICommand OnCloseRequest { get { return new Command(() => CloseAction()); } } /// Returns one based index of the current page. private int CurrentPageIndex { get; } /// Gets the count of carousel pages. private Func PagesCountProvider { get; } /// Action to actuate when close is invoked. private Action CloseAction { get; } } }