本文介绍了WPF 工具包 DatePicker 更改默认值“显示日历"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的 WPF 工具包,特别是 DatePicker.一切正常,但当没有提供任何值时,默认的显示日历"文本出现在 DatePickerTextBox 中.我希望能够在 WPF 中更改此值.

I'm using the latest WPF toolkit, specifically the DatePicker. Everything works fine, but when no value is provided, the default 'SHOW CALENDAR' text appears in the DatePickerTextBox.I want to be able to change this value in WPF.

有人告诉我下载源代码,添加一个新的依赖属性并重新编译为dll.这很酷,但如果发布新版本怎么办?

One told me to download the source, add a new Dependency property and recompile to dll. That's cool but what if new version is released?

这就是为什么我想以这种方式模板化这个控件,我将能够覆盖这个默认字符串.知道怎么做吗?

That's why I'd like to template this control in that way, that I'll be able to override this default string. Any idea how to do that?

谢谢!

推荐答案

好的.我自己找到了解决方案.

OK. I found a solution by myself.

<Style TargetType="{x:Type toolkit:DatePickerTextBox}">
    <Setter Property="Text" Value="Bitte wählen" />
</Style>

无论如何,您必须意识到这一事实,有一个名为 Watermark 的 DependencyProperty,应该设置它来代替 Text.

Anyways, you have to be aware of the fact, that there is a DependencyProperty called Watermark which should be set in place of the Text.

问题是,在最新的 MS 版本(大约 2009 年 6 月)中,他们出于某种未知原因将此属性设为只读.这意味着,这是我编写的唯一 hack,尽管发生了 First-time 异常,因为 DatePicker 正在尝试解析字符串(他假设文本是 Date),但通常您不会注意到它.

The problem is that with the latest MS release (about June 2009) they made this property readonly for some unknown reason. That means, this is the only hack I made up, although there occurs a First-time exception, because the DatePicker is trying to parse the string (he supposes the text to be a Date), but normally you won't notice it.

另一种可能性是直接编辑来自 MS 的源代码并覆盖SetWaterMark() 方法 + 添加您自己的依赖属性(MyWaterMark 或其他东西).但是你不能使用提供的 dll.他们说它会通过 .NET 4 realese 修复,让我们拭目以待.

Another possibility is to edit directly the source code from MS and override the SetWaterMark() method + add your own Dependency Property (MyWaterMark or something). But then you cannot use the provided dll. They said it will come fixed with the .NET 4 realese, let's see.

这篇关于WPF 工具包 DatePicker 更改默认值“显示日历"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 14:36