Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

wpftoolkit - WPF toolkit DatePicker change default value 'show calendar'

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.

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?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OK. I found a solution by myself.

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

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...