c# - Use "real" CultureInfo.CurrentCulture in WPF Binding, not CultureInfo from IetfLanguageTag -


in case:

i have textblock binding property of type datetime. want displayed regional settings of user says.

<textblock text="{binding date, stringformat={}{0:d}}" /> 

i setting language property wpf xaml bindings , currentculture display says:

this.language = xmllanguage.getlanguage(cultureinfo.currentculture.ietflanguagetag); 

but line of code displays text default format of cultureinfo ietflanguagetag of currentculture says, not effective value selected in systems region settings says:

(e.g. "de-de" dd.mm.yyyy used instead of selected yyyy-mm-dd)

region settings: not default yyy-mm-dd used

is there way binding uses correct format without defining converterculture on every single binding?

in code

string.format("{0:d}",date); 

uses right culture settings.

edit:

another way doesn't work desired (like this.language = ... does):

xmlns:glob="clr-namespace:system.globalization;assembly=mscorlib" 

and

<binding source="{x:static glob:cultureinfo.currentculture}"   path="ietflanguagetag"   converterculture="{x:static glob:cultureinfo.invariantculture}" /> 

you can create subclass of binding (e.g. cultureawarebinding) sets converterculture automatically current culture when created.

it's not perfect solution, it's one, since retroactively forcing binding respect culture break other code in wpf depends on behavior.

let me know if need more help!


Comments