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:

Silverlight DatePicker default

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:

DatePicker custom template in Blend

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:

   1: <ContentPresenter x:Name="DropDownDateText" HorizontalAlignment="Center" Margin="0,0,0,0" 
   2:     VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Grid.Column="0" Grid.Row="1" 
   3:     Grid.ColumnSpan="4" Grid.RowSpan="3"/>

Once I had that in place I just went into OnApplyTemplate in DatePicker.cs and after the call to base.OnApplyTemplate() (line 851) I added some additional code:

   1: // change the date to the current date
   2: string DateDay = DateTime.Now.Day.ToString(CultureInfo.CurrentUICulture);
   3:  
   4: // get the Button template and insert the content as current date text
   5: Button b = this.GetTemplateChild(DatePicker.ElementButton) as Button;
   6: TextBlock tb = new TextBlock();
   7: tb.FontFamily = new FontFamily("Arial Bold");
   8: tb.FontSize = 9.5;
   9: tb.FontStretch = FontStretches.Expanded;
  10: tb.UseLayoutRounding = true;
  11: tb.Text = DateDay;
  12: b.Content = tb;

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):

Custom DatePicker with current date text

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.

Hope this helps!

Just a quick shout-out to congratulate the latest Silverlight MVPs to the program.  The Microsoft MVP (Most Valuable Professional) program is a recognition program that is in place to recognize and reward those individuals who have been identified by individuals (peers, Microsoft staff, etc.) as experts in their technology field and global contributors to the technology. 

Microsoft MVP logo

As of today (01 OCT 2009) we welcome some new folks to the Silverlight group:

All of these folks are great participants in the Silverlight ecosystem and I congratulate them for their efforts.  Be sure to check out all the Silverlight MVPs and subscribe to their blogs!  Thanks to all of you for helping make a great developer ecosystem!

Last night I decided to mess around with some older laptops.  I had an HP Pavillion ze2000 CTO laptop (not sure why they call it “CTO” – I guess the Altec Lansing speakers included makes it an executive ;-)).

Works on my machine logoI installed Windows 7 (32-bit) from my home Windows Deployment Server with no problem.  This one took longer than the less-than-20-minute installs I’d been experience.  I’m not sure why.  It wasn’t terribly longer, but about 30-40 minutes I think.  I ran Windows Update and it got all the latest drivers.  A quick check in Device Manager showed no device problems.  Sweet.  I began testing things.  Audio playback was the last thing I played around with.  System sounds, MP3, WMV audio, CD audio…all worked.  Then I put in a DVD (Pirates of the Caribbean to be specific).  The machine suddenly sounded like a machine gun shooting back at me.  Video playback was fine, but audio playback couldn’t work.  I spent a few minutes tinkering then headed to the interweb for help.  My search was hp ze2000 dvd audio not working windows 7 (I type that here in hopes to help some others).  I tried other search terms (dvd audio windows 7 ze2000, dvd audio problems windows 7) and yielded others having problems but no working solution.  Some suggested bad drivers and pointed to older drivers (which I tried and wouldn’t install).

Late in the night I sent a note to my trusty colleague on the Windows test team.  We send a few notes back and forth, then he looped another colleague in and asked me to send the DXDiag report.  2 seconds later I got an email with the classic “try this” note and a few steps.  Boom.  It worked.  I share the works on my machine solution here…it was one of those dreaded checkboxes you wouldn’t think to check.

NOTE: This solution may work and may not.  The fact is that the laptop I have isn’t even a Vista certified machine and the Conexant AC’97 audio driver isn’t supported.  The rep I later talked to was surprised audio even worked at all with Windows 7.  It all works now though!  Your mileage may vary.

THIS IS ONLY A WORK AROUND IF YOU THINK YOU HAVE A SAME PROBLEM ON OLDER MACHINE WHICH USES THE ABOVE AUDIO DRIVER – no need to mess with things working already!

First start up the Sound control panel applet and you’ll see the speakers listed there.  Windows Update found the generic Conexant ACLink Audio driver and installed it already – it indicated that was the latest (date stamp of 2005).

Windows 7 Sound control panel applet

Then choose the properties of the speakers and head to the advanced tab.  When there, UNCHECK the box that reads Allow applications to take exclusive control of this device.

Speaker properties advanced tab

Once unchecked, my DVD audio worked.  Other audio still worked as well. 

Random checkbox setting huh?  I would have taken a long time to get to that setting.  Hopefully this helps others who might be braving upgrading older laptops to Windows 7.  And yes, it runs Windows 7 great.

Most of you who are Microsoft developers probably are aware of Channel 9 and have benefited both from the deep technical screencasts to the behind-the-scenes interviews that the team has provided with such luminaries as Anders Hejlsberg, Scott Guthrie, Bill Gates, etc. 

Tina Summerford and the C9 crew produced what I feel is one of (dare I say number one?) the best Channel 9 pieces of content yet (besides the ScottGu intro video for MIX09).  Today they present to you The Visual Studio Documentary in two parts (with full detailed interviews to be posted later).  You can view Part One and Part Two today.  I suggest you take a moment and gather the other geeks in your company, find a conference room and watch them.  Insights from Anders, ScottGu, Tony Goodhew, JasonZ about the history of what we know now as Visual Studio and the .NET Framework…and the bumps along the way.

You also get to hear about the other “Ruby” project, and how the team struggled from bundling a bunch of different products to creating an integrated development environment and platform – oh and learn what ScottGu does over his holiday breaks too.

It is well produced, has some very interesting points I didn’t know about myself.  I really enjoyed this one and hope you take a moment to enjoy it as well.

Mithun just posted that the videos are now available online from the Silverlight Firestarter Seattle event.  You can view the videos here in WMV form, but I also took a quick stab at putting them together in a playlist using the Silverlight Expression Encoder templates.  Here they are:

You can click the little icon in the upper right to see the playlist option and to navigate. 

NOTE: The offline mode doesn’t seem to work and likely because I didn’t populate the playlist option with the sizes of the videos, sorry about that, but just wanted to put these together conveniently and quickly.

It was a great time and I was sad I didn’t have time to stay for the QA panel for participation.  Thanks for all of you attending in person at this and the other Seattle area events…as well as those who attended online!