Do you want the good news, or the bad news ?
The good news is that Microsoft says that this issue has been fixed in the Feb 2010 release of the WPFToolkit. And it has.
The bad news is that, although setting a DatePicker's IsEnabled value to "True" will enable the DatePicker, so you can now click on the Calendar button to pick a date, it will still look disabled.
"Bug" ? Did I say the word "bug" ?
Of course not.
You can get around this issue by applying a <Style>
though.
Below is some simple xaml code to demonstrate.
It displays two rows, each containing a CheckBox and a DatePicker.
When you click on a CheckBox in a row, it should enable the DatePicker in that row.
This shows the difference between a DatePicker without a Style (in the first row), and a DatePicker with a Style (in the second row).
Both DatePickers do get enabled/disabled correctly, but the one in the first row never looks as though it is. The DatePicker in the second row uses a Style
to show the user when it's disabled.
Notice how this code sets the Background of both the DatePicker
control and of the DatePickerTextBox
part of it.
<Window x:Class="WPFDatePickerTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit"
Title="Window1" Height="317" Width="461">
<Window.Resources>
<Style TargetType="{x:Type primitives:DatePickerTextBox}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="DatePickerStyle1" TargetType="{x:Type wpf:DatePicker}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{x:Static SystemColors.InactiveBorderBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<WrapPanel>
<CheckBox Height="16" Name="cbDateOfJoining" Width="120">Date of joining</CheckBox>
<wpf:DatePicker Height="25"
Name="datePicker1"
Width="140"
IsEnabled="{Binding IsChecked, ElementName=cbDateOfJoining}" />
</WrapPanel>
<WrapPanel>
<CheckBox Height="16" Name="cbDateOfLeaving" Width="120">Date of leaving</CheckBox>
<wpf:DatePicker Height="25"
Name="datePicker2"
Width="140"
IsEnabled="{Binding IsChecked, ElementName=cbDateOfLeaving}"
Style="{DynamicResource DatePickerStyle1}" />
</WrapPanel>
</StackPanel>
</Grid>
</Window>
Hope the helps !
And I hope that it's properly fixed in the next WPFtoolkit release. Users have been complaining about this issue since 2009...