private void AttachGestures(KeypadLabel label, object value) { label.GestureRecognizers.Add(new PressedGestureRecognizer() { Command = PressedCommand, CommandParameter = new GestureEventArgs() { Sender = label, Value = value } }); }
private void DefineKeys() { var backgroundColor = Color.Black; var textColor = Color.White; for (int i = 0; i < 9; i++) { var label = new KeypadLabel() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = backgroundColor, TextColor = textColor, Text = (i + 1).ToString(), HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; AttachGestures(label, i + 1); this.Children.Add(label, i - ((i / 3) * 3), i / 3); } this.Children.Add(new KeypadLabel() { BackgroundColor = backgroundColor, TextColor = textColor, Text = "", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }, 0, 3); var zeroLabel = new KeypadLabel() { BackgroundColor = backgroundColor, TextColor = textColor, Text = "0", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; AttachGestures(zeroLabel, 0); this.Children.Add(zeroLabel, 1, 3); var backLabel = new KeypadLabel() { BackgroundColor = backgroundColor, TextColor = textColor, Text = BackCharacter, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; AttachGestures(backLabel, BackCharacter); this.Children.Add(backLabel, 2, 3); }