WPF formatting labels with StringFormat

后端 未结 2 2203
难免孤独
难免孤独 2021-02-14 10:04

I have a WPF application. I have some labels and some datagrids which are bound to some public properties. Some of these properties are numerical values.

In the datagrid

2条回答
  •  孤城傲影
    2021-02-14 10:22

    Just a quick addition I'd like to post along these lines in case anyone else runs in to it... My application uses localization since it has multi-country support, but we also support user's system settings. We noticed ContentStringFormat defaults to your UI culture.

    That caused an issue in one of our forms where the user's machine-specific decimal places they had configured in windows settings were not respected when you specified the ContentStringFormat.

    Since the ContentPresenter simply takes the string format without the converter culture you could normally specify in the binding , this means that a format of say: 0:N will only return two decimal places if English is my current UI culture, even though I have 5 decimals specified on my windows settings.

    In our case we applied some binding overrides to work around this, but mainly just wanted to add this extra bit of info in case anyone else runs in to it ;)

提交回复
热议问题