Skip to content

Instantly share code, notes, and snippets.

@dhindrik
Last active July 17, 2020 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhindrik/45981788c9c56c778c3966ed66b70abe to your computer and use it in GitHub Desktop.
Save dhindrik/45981788c9c56c778c3966ed66b70abe to your computer and use it in GitHub Desktop.
public class Button : PancakeView
{
public static BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(Button));
public static BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(Button));
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public double AnimationScale { get; set; } = 0.9;
public Button()
{
Padding = new Thickness(10);
BackgroundColor = Color.FromHex("#388E3C");
Shadow = new DropShadow()
{
Offset = new Point(3, 3),
BlurRadius = 5,
Color = Color.White
};
var tapRecognizer = new TapGestureRecognizer();
tapRecognizer.Tapped += TapRecognizer_Tapped;
GestureRecognizers.Add(tapRecognizer);
}
private async void TapRecognizer_Tapped(object sender, EventArgs e)
{
var view = (View)sender;
await view.ScaleTo(AnimationScale);
if (Command != null && Command.CanExecute(CommandParameter))
{
Command.Execute(CommandParameter);
}
await view.ScaleTo(1.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment