Create a rounded corner text box in WPF

Source: Internet
Author: User

I thought that the XAML in WPF would be very powerful and many attributes can be set, such as the rounded corner attribute of the text box. Unfortunately, this attribute does not exist. However, it was unexpectedly discovered that the Border has the CornerRadius attribute. We can use it to set the Border effect of the Border.

The main code of XAML is as follows:

<Border CornerRadius = "5" Height = "35" Margin = "142,137,202,139" BorderThickness = "1" BorderBrush = "# FF737070">
<TextBox Height = "32" Name = "textBox1" Width = "156" Background = "{x: Null}" BorderThickness = "0" FontSize = "22"/>
</Border>

Note that the BorderThickness attribute of Border is to set the Border width of this Border, while that of BorderBrush is the Border color. The TextBox's Background is set to transparent ("{x: Null}"), and BorderThickness is the border of the text box. We can remove it and set it to 0. This is equivalent to hiding the TextBox, but it exists and can still be input. We just use the Border's appearance to replace the TextBox...

The effect is as follows:

 

 

Of course, since these attributes can be defined, we can encapsulate them as a dll Control and customize the rounded corner attribute of the control. Then we can use it perfectly...

 

If you want to reprint it, please indicate the author and the source. Thank you!

 

 

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.