sharee.bike-App/TINKLib/ViewModel/Info/BikeInfo/BikeInfoCarouseltemViewModel.cs
2021-07-14 19:57:07 +02:00

80 lines
2.3 KiB
C#

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<int> 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;
}
/// <summary> Gets the title of the navigation page. </summary>
public string Title { get; }
public bool IsImageVisble { get; }
/// <summary> Gets the image. </summary>
public ImageSource Image { get; }
/// <summary> Gets the text which describes the image. </summary>
public string DescriptionText { get; }
/// <summary> Get the progress of the carousselling progress.</summary>
public double ProgressValue
{
get
{
var l_oCount = PagesCountProvider();
return l_oCount > 0 ? (double)CurrentPageIndex / l_oCount : 0;
}
}
/// <summary> Gets if user can leave carousel page.</summary>
public bool IsCloseVisible
{
get
{
return PagesCountProvider() == CurrentPageIndex;
}
}
/// <summary> Command object to bind close button to view model. </summary>
public ICommand OnCloseRequest
{
get
{
return new Command(() => CloseAction());
}
}
/// <summary> Returns one based index of the current page. </summary>
private int CurrentPageIndex { get; }
/// <summary> Gets the count of carousel pages. </summary>
private Func<int> PagesCountProvider { get; }
/// <summary> Action to actuate when close is invoked. </summary>
private Action CloseAction { get; }
}
}