How to get a MouseLeftButtonDown or MouseLeftButtonUp Event from TextBox in Silverlight ?

In Silverlight, the event leftclickbutton for textbox control does not work. to solve this problem, simply create the following class:
namespace Utils
{
    public class TextBoxClickable : TextBox
    {
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            e.Handled = !base.Focus();
        }
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            e.Handled = !base.Focus();
        }
    }
}

Your XAML should define your namespace:

And you can use your new clickable TextBox like this:

No comments:

Post a Comment