When you add a mouseleftbuttondown event to a control, this event cannot always be triggered. The control sets "handled" to "true" after the mouseleftbuttondown event is captured ". In Event Routing, when a control obtains a routedevent, it detects the handled attribute. If the handled attribute is true, the event is ignored.
Solution:
Use the uielement. addhandler method (routedevent, Delegate, Boolean). This method contains the handledeventstoo parameter of the system. boolean type. If this parameter is set to true, even if the routing event is marked as handled (handled is true) in its event data, event processing is called.Program. If it is false, it is marked as handled (handled is true) and no event handler is called. The default value is false.
BackgroundCodeAs follows:
Public moniterdatagrid ()
{
Initializecomponent ();
Searchtextbox. addhandler (textbox. mouseleftbuttondownevent, new mousebuttoneventhandler (this. searchtextbox_mouseleftbuttondown), true );
}
Private void searchtextbox_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
{
Searchtextbox. Text = string. empty;
}