This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21360|Reply: 0

[WPF] The WPF TextBox control implements vertical centering of Chinese characters

[Copy link]
Posted on 12/22/2017 1:56:49 PM | | | |
In the TextBox control, the text is vertically centered

When the TextBox has a long vertical length but a small font, you will find that the text is not vertically centered when you type. In use, we found that although TextBox can set the horizontal alignment of text, there is no corresponding attribute for us to adjust its vertical alignment. Fortunately, TextBox inherits from the Control class, and can change its attribute style by modifying the Template template (TextBlock inherits from FrameworkElement, cannot be edited by template).


Finally, apply the style.

PS

A content host is an element used to render the content of a TextBox. The TextBox's ControlTemplate must contain only one element that is labeled as a content host element. To mark an element as a content host, you should give it a special name PART_ContentHost. The content host element must be a ScrollViewer or an AdornerDecorator. The content host element may not host any child elements.

The effect is as follows:







Previous:Implement two ways to select the navigation menu
Next:What is the difference between the Window.Loaded and Window.ContentRendered events?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com