c# - DateTimePicker + WPF + binding + accept dd/MM/yyyy via userinput -



c# - DateTimePicker + WPF + binding + accept dd/MM/yyyy via userinput -

simplified question:

i have datepicker in wpf. come in value 30/10/1983 in textbox of datepicker. need value posted viewmodel, in have bound datetime? property.

is there way can accomplish this. mm/dd/yyyy format triggers postback not dd/mm/yyyy.

the datepicker code below.

<datepicker grid.row="2" name="inputdate" text="{binding birthdate,mode=twoway,updatesourcetrigger=propertychanged}" > </datepicker>

the view model property below.

private datetime? birthdate; public datetime? birthdate { { homecoming this.birthdate; } set { this.birthdate = value; onpropertychanged("birthdate"); } }

i come in value 10/10 datepicker textbox, setter gets called value, moment come in entire date 30/10/1983, still have view model property equal null.

i have changed format english-unitedkingdom, in calendar settings, , currentculture reflects en-gb appropriately.

original question:

i have datetimepicker command in wpf, have bound text property nullable datetime in view model.

the problem facing when come in value in format mm/dd/yyyy, value postback in view model, indicating new value.

but when come in value in dd/mm/yyyy format, not notification in view model , value lost. bound propertyin view model null.

the short date format 1 have specified in calendar settings & dateformat, within short date format provide entry "dd/mm/yyyy".

could please help me scenario in take date in dd/mm/yyyy format, , not want hardcode, wish pick short date format calendar settings , also, wish recieve updated value in view model too.

the problem related not valid date not set right value viewmodel datetime property. so, can intercept , convert correctly converter.

an example:

public object convert(object value, type targettype, object parameter, cultureinfo culture) { string strvalue = system.convert.tostring(value); datetime resultdatetime; if (datetime.tryparse(strvalue, out resultdatetime)) { homecoming resultdatetime; } homecoming value; }

and xaml code like:

<datepicker text="{binding birthdate,mode=twoway,updatesourcetrigger=propertychanged}" selecteddate="{binding relativesource={relativesource self},path=text, converter={staticresource dateconverter}}" />

c# wpf datetime datetimepicker

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -