Implementation and use of the placeholder behavior PlaceHolderBehavior, placeholderbehavior

Source: Internet
Author: User

Implementation and use of the placeholder behavior PlaceHolderBehavior, placeholderbehavior

I cannot describe this effect on PlaceHolder literal translation placeholders. Some people call this effect watermark effect as intuitive as the PlaceHolder attribute of html5:

Usage:

First, download the identifier line dll.rar to reference the dll in the project.

1. In

Reference System. Windows. Interactivity. dll assembly

 

Add reference on the xmal page:

Then attach to TextBox

 

Set behavior attributes

The Text value must be set. This is the prompt Text, and other attributes are set as needed. If it is not set, the value of the appended TextBox is used by default.

2. In Blend

It's very simple in blend, just drag it to the TextBox.

Set attributes

 

========================================== ========================================================== =

This effect is very common and has nothing to do with the business. It is very suitable for Behavior to facilitate use in different projects without changing the control template.

The following describes the implementation methods:

The TextBox contains a component: PART_ContentHost used to display text.

So the simplest implementation method I think of is to add a TextBlock on this part to display the prompt information, and hide the TextBlock when the Length of the TextBox Text is greater than 0, the TextBlock is displayed when Length = 0.

In this case, you need to take out this part, put a Grid, add TextBlock to the Grid, and then put the entire Grid back to its original position.

Since the component's parent level can put down this FrameworkElement type part, it must inherit from one of the Decorator or Panel. the Decorator has the Child attribute and the Panel has the Children attribute. (You may change the control template to a Grid or another. If you do not change the template, It is inherited from the Decorator)

In this way, you can find this part and its parent level to achieve this effect.

Panel: StackPanel, DockPanel, Grid, Canvas

Six dependency attributes: Text, FontSize, Foreground, HorizontalAlignment, verticalignment, and Margin

If your personal abilities are limited, you are welcome to correct them.

 

The complete Demo source code is attached: The runner-up code .rar.

 

 

Thank you very much for reading the original content of this article. It is not easy to write articles. If you feel this article is helpful to you, please click "recommended". Please repost it. Please note the link to this article.

 

 

We recommend a good Blend, Wpf, and sl Communication Group.

Group number: 152049269

Thank you!

Related Article

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.