[Silverlight entry series] custom control searchtextbox (1): remove the focus border

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.