This past weekend during a conversation about Silverlight controls at the San Diego Silverlight Education Day, someone asked about the DatePicker control and why the “15” is there and how come they can’t change it. Here’s the control that was being referred to:

The calendar displays an icon to the right of the text box area which, when clicked, displays a drop-down calendar picker. The icon always says “15” and is intended to look like a little calendar date sheet (you know, like those desk calendars).

The question was how to change that icon. Well, easily. You can easily edit the template using Blend and drill into the UI parts and change it. I opened Blend, chose to edit the template, then edit the Button template and you’ll see that the “15” is actually a Path:

Now that I know where that template is, I can put anything i want there to replace the Path data to anything I want. But the question was raised as to why it doesn’t show the current date text instead. So on the plane ride back I did a quick refactor to see how easy that could be done.

After getting the Ms-PL licensed source code for the DatePicker control from the Silverlight Toolkit, I had access to the full source of the control to get the inner guts. Here’s what I did.

First, I changed generic.xaml (located in Themes folder) definition of DatePicker style/template. I changed the Path to a ContentPresenter (about line 437 in the generic.xaml file). I removed the Path and replaced it with this:

What this does is basically use the local time information to get the current Day text and put that TextBlock as the Content for the button…the result is that the DatePicker now will display the number for the current Date (I took this screenshot on 05 OCT 2009):

So if I wanted this then I could recompile the source and use my custom DatePicker in my application. The key difference in this modification is that I’m not using a Path, but a TextBlock.

I’m not sure if this is useful, but since the question was posed and I had time to kill, I thought I’d post my findings. Having access to the source control for all the Silverlight controls is a great way to customize/extend exactly what you need as well as serving as a great learning resource for you in your control development.