Thomas Lindner
Thomas Lindner

Reputation: 61

WP7: Windows Phone 7: EventHandle seems looping

I would like to have an EventHandle for a MouseLeftButtonDown event. When called/fired the last character of a string should be removed. My code looks like this:

 public string MyString;

 private void OnMouseDownDelete(object sender, MouseButtonEventArgs e)
 {
     int MyStringLength = MyString.Length;
     MyStringLength = MyStringLength - 1;
     MyString = MyString.Substring(0, MyStringLength);
 }

But when I run this code a MouseLeftButtonDown event will start a loop until the string becomes empty.

Who can tell me what I am missing?

Upvotes: 0

Views: 141

Answers (1)

Metro Smurf
Metro Smurf

Reputation: 38335

Since you are using Mango (7.1), you can use the Tap Event instead of the MouseLeftButtonDown event.

However, I suspect that the event is firing multiple times which is causing the deletion of the string.

A good practice is to use the Handled property so that other control's do not try to handle the same event:

private void OnMouseDownDelete(object sender, MouseButtonEventArgs e)
{
     int MyStringLength = MyString.Length;
     MyStringLength = MyStringLength - 1;
     MyString = MyString.Substring(0, MyStringLength);

     e.Handled = true;
}

You may need to post all the code that shows how the MouseLeftButtonDown event is being added.

Upvotes: 2

Related Questions