Silverlight: application of the updatesourcetrigger attribute

Source: Internet
Author: User

In the bindingexpression of Silverlight/WPF, we can define the updatesourcetrigger attribute for a bind. However, in Silverlight, only explicit updates and default methods are provided (triggered when focus is lost ),

Therefore, if we need to update the data source when entering Textbox, we need to further process it. If you are familiar with this function, you can quickly search for code similar to the following on the Internet:

 
Textbox TXT = senderAsTextbox;

VaR bindingexpression = TXT. getbindingexpression (textbox. textproperty );

If(Bindingexpression! =Null)

 
{

Bindingexpression. updatesource ();

 
}

In this article, I follow the method of extending the additional attributes of the previous grid. To implement this function, first declare updateexplictproperty.

 
Public Static BoolGetupdateexplict (dependencyobject OBJ)

{

 
Return(Bool) Obj. getvalue (updateexplictproperty );

 
}

Public Static VoidSetupdateexplict (dependencyobject OBJ,Bool Value)

{

 
OBJ. setvalue (updateexplictproperty,Value);

}

Public Static ReadonlyDependencyproperty updateexplictproperty =

Dependencyproperty. registerattached ("Updateexplict",Typeof(Bool),Typeof(Textboxextension ),NewPropertymetadata (False, Updateonpropertychangedpropertycallback ));

In updateonpropertychangedpropertycallback, The textchanged of the textbox is processed. The processing logic here isCodeYes.

When we use this additional property, we can use the following XAML:

<Textbox Text= "{Binding firstname, mode = twoway }" Updatetextbox: textboxextension.Updateexplict= "True"> </Textbox>

In fact, for this function, you can also use behavior to encapsulate the two recently released articles.ArticleThey all use additional attributes to solve the problem. In fact, they also emphasize the significance of additional attributes in the Silverlight project application.

 

 

Download Code: textboxextension.rar

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.