WPF outsourcing company-Beijing node flying software WPF 4.5 exploring four new binding delay attributes

Source: Internet
Author: User
If you read the msdn page of The New WPF 4.5 feature, you will find "automatically updated data binding source" under its tag ". But for me, it is more accurate to understand that the "delay" attribute is added to the bound add extension. More wpf4.5 exploring series of articles

This article is part of the new feature series for WPF 4.5. by reading this article, you will find that the purpose of this attribute, how to use it, and under some conditions are quite useful.

What is this attribute?

Binding must be completed between two objects: the source (where the data comes from) and the target (where the data is going ). For example, if you bind the text attribute of a textblock to your viewmodel attribute "name", the target and source of the textblock are your viewmodel.

The binding will be executed simultaneously between two attributes. When the binding is completed only in twoway mode, the target can update the data source value (textblock can update viewmodel ).

How to use this attribute?

Because this is an additional binding property, you must define it on each binding you create.

Latency is defined in milliseconds. The default value 0 is a classic binding constraint.

The following is an example of binding, with a latency of 500 milliseconds:

<Textblock text = "{binding name, delay= 500}"/>

Latency is only applied in one direction: from the target to the source.

When will this attribute be used?

Some people may initially think that this is not a useful function, but after a while, they will find it useful in some scenarios.

1. msdn pointed out that there are some components, such as the slider, there is no need to update the source value for each pixel that the slider moves.

2. Similarly, you can use this attribute in the text box to Enter text blocks instead of letters or letters.

 

Beijing node flying with more than four years of WPF outsourcing development experience, welcome to contact us for business consulting

QQ: 372900288

Email: SLteam@vip.qq.com

 

3. It can be used for Master/details scenarii. When the change option triggers some time-consuming processing on the UI thread.

4. In the same case, if you start an asynchronous project for each change, it can be saturated with many thread pools (or cause excessive network usage ).

5. Sometimes, in master/details scenarii, the detailed view is quite complex and time is required to present it. In this case, latency can trigger rendering, but only when it is useful.

For example:

Master/detail scenarii is very useful. It is illustrated in an example. For example, we select another "person" column and select a detailed display from it, next we will see the following interface:

  

 

Each time you change the selected person, a time-consuming process will be triggered on the UI thread in the setter, through the thread. Sleep call for simulation:

Public Person selectedperson
{
Get {return _ selectedperson ;}
Set
{
_ Selectedperson = value;
// Simulate time consuming operation
Thread. Sleep (500 );
Raisepropertychanged ("selectedperson ");
}
}

If no latency is set, the navigation in the list is slow and the user interface for each change is frozen. Just let the "Down Arrow" key make the UI freeze a little too large. You can easily use the keyboard navigation list by setting the latency attribute to 500 milliseconds.

<ListBox itemssource = "{binding persons}" selecteditem = "{binding selectedperson, delay= 500}"/>

Finally, add a button to trigger a source object, which proves that the delay project only changes in one direction.

After registration, the complete code source for the demo can be found in the folder.

It is a supplement to the WPF framework, and it is also very useful! If you want more information, read the msdn page of this new property.

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.