Prism 本地化问题:未使用正确的数字和日期时间格式
我有一个使用 Prism 4.0 编写的应用程序。它有很多视图,这些视图具有绑定到 ViewModel 属性的不同控件(我的应用程序中没有模型)。其中一些控件可视化日期时间和小数值。在某些地方,字符串表示形式具有正确的格式,但在某些地方则不然。但是,如果我将这些小数和日期时间属性表示为字符串属性并对基础值调用 ToString() 方法,那么它们的格式将是正确的。所以我的 ViewModel 线程的 CurrentThread.CurrentCulture 是正确的。但是数据绑定器或 Prism 或任何将日期时间和十进制值转换为字符串线程区域性的代码似乎不正确,或者它们可能根本不使用当前区域性。我的调试技能还不足以进入幕后,但我认为魔法就在这里发生(堆栈跟踪):
[Native to Managed Transition]
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.GetValue(object item, int level)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue(int k)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue()
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.RawValue()
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange)
PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(object o, string propName)
关于如何强制 WPF 和 WPF 的任何想法Prism 在任何地方使用正确的数字和日期时间格式?
I have an application written using Prism 4.0. It has lots of Views which have different controls which bind to ViewModel properties (I don't have Models in my app). Some of those controls visualize datetime and decimal values. In some places the string representations have correct format, but in some places they don't. But if I represent those decimal and datetime properties as string properties and call ToString() methods on the underlying values, then their format will be correct. So CurrentThread.CurrentCulture of my ViewModel thread is correct. But the data binder's or Prism's or whatever code converts datetime and decimal values to strings thread culture seems to be incorrect, or maybe they are not using current culture at all. My debugging skills are not sufficient yet to go behind the curtains, but I think that magic happens here (stack trace):
[Native to Managed Transition]
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.GetValue(object item, int level)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue(int k)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue()
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.RawValue()
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange)
PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange)
PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(object o, string propName)
Any ideas how to force WPF & Prism to use correct number and datetime format anywhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将以下代码行放入启动代码中可能会解决该问题:
这会将所有 WPF 控件的 LanguageProperty 设置为当前区域性。
Placing the following line of code in your startup code may fix the issue:
This will set the LanguageProperty for all WPF controls to the current culture.