c# – WPF DatePicker Watermark使用错误的语言,但Dateformat是正确的

我有一个非常奇怪的问题:

在我的机器上,DatePicker根据我想要设置的语言/文化更改其水印和日期格式.

如果我将我的应用程序复制到其他计算机后发生:

在某些计算机上,它的工作方式与我的机器相同.在其他计算机上只有日期格式更改,但水印没有!不用说,拥有一个例如日期选择器是非常难看的.德国日期,但英国水印.

这种行为的原因是什么?

对于i18n,我使用以下代码

App.xaml.cs:

public partial class App : Application
{
    public App()
    {
        CultureInfo ci = new CultureInfo("de-DE"); 
        Thread.CurrentThread.CurrentCulture = ci;
        Thread.CurrentThread.CurrentUICulture = ci;
    }
}

WindowMain.xaml.cs:

public partial class WindowMain : RibbonWindow
{
    public WindowMain()
    {
        this.Language = XmlLanguage.GetLanguage("de-DE");
        this.InitializeComponent();
    }
}

解决方法

有一点我可以说,DatePicker中的Watermark实现了bug,没有简单的访问权限.也许,由于这种困难,文本的本地化不起作用. @Matt Hamilton有一篇很棒的文章,引自 here

Something that a lot of people (myself included) don’t like about the DatePicker,though,is that by default if no date is displayed it shows the text “Select a date” as a watermark,and this text is baked into the control – it’s not localized or accessible by any public property. This is particularly frustrating if the date in question is optional and you don’t necessarily want to prompt your users to select one.

在同一篇文章中,他提供了如何访问Watermark的决定.这里:

How to localize the WPF 4.0 DatePicker control

@Wayne Maurer以附加依赖属性的形式创建了一个通用解决方案:

<DatePicker Grid.Row="2" 
            local:DatePickerWatermarkBehavIoUr.Watermark="Select the date" />

您需要基于当前的文化,设置水印的文本,例如使用上面的例子.

注意:在DatePicker的Silverlight to Watermark中进行访问[link]:

DatePickerTextBox Box = base.GetTemplateChild("TextBox") as DatePickerTextBox;
Box.Watermark = "Type or select a date --> ";

相关文章

原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...
c语言输入成绩怎么判断等级
字符型数据在内存中的存储形式是什么