Billing/Billing.Shared/UI/CustomControl.cs

63 lines
1.8 KiB
C#

using System;
using Xamarin.Forms;
namespace Billing.UI
{
public class TintImage : Image
{
public static readonly BindableProperty PrimaryColorProperty = BindableProperty.Create(nameof(PrimaryColor), typeof(Color?), typeof(TintImage));
public Color? PrimaryColor
{
get => (Color?)GetValue(PrimaryColorProperty);
set => SetValue(PrimaryColorProperty, value);
}
}
public class LongPressButton : Button
{
public event EventHandler LongPressed;
public LongPressButton()
{
Padding = 0;
BackgroundColor = Color.Transparent;
}
public void TriggerLongPress()
{
LongPressed?.Invoke(this, EventArgs.Empty);
}
}
public class LongPressGrid : Grid
{
public static readonly BindableProperty LongCommandProperty = BindableProperty.Create(nameof(LongCommand), typeof(Command), typeof(LongPressGrid));
public static readonly BindableProperty LongCommandParameterProperty = BindableProperty.Create(nameof(LongCommandParameter), typeof(object), typeof(LongPressGrid));
public Command LongCommand
{
get => (Command)GetValue(LongCommandProperty);
set => SetValue(LongCommandProperty, value);
}
public object LongCommandParameter
{
get => GetValue(LongCommandParameterProperty);
set => SetValue(LongCommandParameterProperty, value);
}
public void TriggerLongPress()
{
var command = LongCommand;
if (command == null)
{
return;
}
var parameter = LongCommandParameter;
if (command.CanExecute(parameter))
{
command.Execute(parameter);
}
}
}
}