How to Write a custom Silverlight control searchtextbox, similar effect:
The first thing that comes to mind is to extend the textbox control to implement the watermark function, but this style takes a little effort.
After running, a serious problem is found, that is, the textbox automatically has the border effect when the mouse passes through and the focus, which seriously affects the effect.
How do I remove the focus and hover borders of the default textbox? As longModify the template of the default Textbox Control, set the borderthickness of focus and hover to 0, or set the transparency to 0.You can.
Specific practice: Write a class that inherits Textbox,CodeAs follows:
Using System. windows;
Using System. Windows. controls;
Namespace Mycontrols
{
Public Class Nofocustextbox: textbox
{
Public Override Void Onapplytemplate ()
{
Foreach ( String S In " Focusvisualelement, mouseoverborder " . Split ( ' , ' ))
{
VaR BDR = Gettemplatechild (s) As Border;
If (BDR ! = Null )
{
BDR. borderthickness = New Thickness ( 0 );
}
}
Base . Onapplytemplate ();
}
}
}
OK. The effect is achieved.
The next section describes how to implement the source code of the searchtextbox custom control for top display. Stay tuned.