Reputation: 135
I would like to add an hold gesture to a C# created button. But all solution that I've found on the internet don't work. I post the part of the code involved the creation of the button:
var button = new Button();
button.Click += new RoutedEventHandler(ButtonClickOneEvent);
button.Hold += new TypedEventHandler<GestureRecognizer, HoldingEventArgs>(holder_recon);
The button.Hold
doesn't work and it gives me an error.
For now, I want holder_recon
, the function that should start when the button is held, give execute MessageBox.Show("Held")
.
Can you please help me?
Upvotes: 0
Views: 8914
Reputation: 2778
May this will help you.
var button = new Button();
button.VerticalAlignment = System.Windows.VerticalAlignment.Top;
button.Height = 75;
button.Tag = tag;
button.Background = new SolidColorBrush(colore);
button.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
button.Click += button_Click;
button.Hold += button_Hold;
private void button_Hold(object sender, System.Windows.Input.GestureEventArgs e) => MessageBox.Show("Hold");
private void button_Click(object sender, RoutedEventArgs e) => MessageBox.Show("Click");
Upvotes: 1