xaml - WPF: Initializing a TextBox and binding it to a validation rule -
i try validate ip-address user enters text box of wpf dialog. text box supposed initialized 127.0.0.1. xaml:
<textbox height="23" width="98" verticalalignment="top" horizontalalignment="left" name="ip_address" text="127.0.0.1"> <textbox.text> <binding path="left" updatesourcetrigger="propertychanged"> <binding.validationrules> <local:ipvalidationrule /> </binding.validationrules> </binding> </textbox.text> </textbox>
this attempt bind text box validation rule causes error, because attribute text has value 127.0.0.1. question this: how can achieve initializing , binding simultaneously?
regards, rsel
ps: initializing text box in window_loaded doesn't work either. box remains empty. without binding rule works.
a couple options:
set initial value in property textbox bound to. binding should pick when control loads. i'm not sure if meets goals though.
use targetnullvalue property of binding object specify show when source null.
here's msdn on option 2:
http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx
Comments
Post a Comment