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