【问题标题】:Prism localization issue: correct number and datetime format is not usedPrism 本地化问题:未使用正确的数字和日期时间格式
【发布时间】:2012-02-03 12:29:55
【问题描述】:

我有一个使用 Prism 4.0 编写的应用程序。它有很多视图,它们具有绑定到 ViewModel 属性的不同控件(我的应用程序中没有模型)。其中一些控件可视化日期时间和十进制值。在某些地方,字符串表示具有正确的格式,但在某些地方却没有。但是,如果我将这些十进制和日期时间属性表示为字符串属性并在基础值上调用 ToString() 方法,那么它们的格式将是正确的。所以我的 ViewModel 线程的 CurrentThread.CurrentCulture 是正确的。但是数据绑定器或棱镜或任何将日期时间和十进制值转换为字符串线程文化的代码似乎不正确,或者他们可能根本没有使用当前文化。我的调试技能还不足以隐藏在幕后,但我认为这里发生了魔法(堆栈跟踪):

    [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 和 Prism 在任何地方使用正确的数字和日期时间格式?

【问题讨论】:

标签: .net wpf localization prism currentculture


【解决方案1】:

在您的启动代码中放置以下代码行可能会解决问题:

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));  

这会将所有 WPF 控件的 LanguageProperty 设置为当前区域性。

【讨论】:

  • 是的,这实际上是我在从 cmets 中的链接阅读帖子后修复它的方式。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多