xaml - WPF Binding StringFormat Short Date String -


i use short date named string format in wpf.

i tried like:

<textblock text="{binding date, stringformat='short date'}" /> 

how this?

try this:

<textblock text="{binding propertypath, stringformat=d}" /> 

which culture sensitive , requires .net 3.5 sp1 or above.

note: case sensitive. "d" short date format specifier while "d" long date format specifier.

there's full list of string format on msdn page on standard date , time format strings , fuller explanation of options on this msdn blog post

however, there 1 gotcha - outputs date in format unless set culture correct value yourself.

if not set property, binding engine uses language property of binding target object. in xaml defaults "en-us" or inherits value root element (or element) of page, if 1 has been explicitly set.

source

one way in code behind (assuming you've set culture of thread correct value):

this.language = xmllanguage.getlanguage(thread.currentthread.currentculture.name); 

the other way set converter culture in binding:

<textblock text="{binding propertypath, stringformat=d, converterculture=en-gb}" /> 

though doesn't allow localise output.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -