在我的机器上,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(); } }
解决方法
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 --> ";