wpf - C# XAML Binding of a default with IValueConverter -
i'm looking reason why code isn't doing job: in xaml use:
<textbox text="{binding path=txt_8, converter={staticresource defkonverter}, converterparameter='useralias'}"/>
in c# there ivalueconverter giving me default value when converterparameter='useralias'. ex. string 'jettero'. works point see in textbox text 'jettero'. saving record database, in record txt_8 still null ! (other fields saved well) looks binding not updating record field behind textbox.
=========== update start
conclusion: not working because binding working in 1 direction. converter showing special things makes user experince better not save it.
=========== update end
a similar issue backward happens also, in xaml:
<textbox text="{binding path=date_1, converter={staticresource defkonverter}, converterparameter='\{0:yyyy-mm-dd\}timestamp'}"/>
this working should in record behind: when write in textbox '.' character 'translates' today's date. after save record, contains date. in textbox still see written '.'. in sit binding not updating textbox on record.
=========== update start
conclusion: not working because binding working in 1 direction. converter change data in shape how wanna store.
what still not answered: when convert '.' present date, not showing - see reason. in converter if i'm using modal window somehow extend data wrote in (finding full text keyword), extended information shows in textbox beside store of it.
=========== update end
i don't know miss... checked lot of using of default , ivalueconverter solutions, simple sit never came up. can help?
i think might expecting behaviour value converter wasn't designed. happening is:
on rendering textbox, binding reads value, let's null
, property txt_8, passes converter, gives value render, in example 'jettero'. means visual representation of null
jettero
. isn't meant (and won't) consequently replace null 'jettero' because, according binding engine, has loaded value source , returned target.
the convertback
method of value converter supposed cater scenario value changed on ui , needs converted storage.
moral of story: don't use value converter specifying "default" value binding. if property needs default value, assign in constructor or initializer. if want property value change assigned value, implement there, instead of in converter.
for instance, can define date property instead of using converter:
// disclaimer: untested pseudo-code private datetime? _datetimefield; public string somedateproperty { { return _datetimefield.tostring('dd-mm-yyyy'); } set { if (value == '.') value = datetime.today.tostring(); _datetimefield = datetime.parse(value); } }
Comments
Post a Comment