General Discussion Event SelectedDateChanged doesn't work (WPFControlToolkit)

Nov 19, 2008 at 8:50 AM
Hello,

I've use WPF ToolKit in a ressource dictionary, and the selectedDate is always null

Here is the code from controls.generic.xaml :


1 <!-- labeled DatePicker --> 
2  
3     <Style TargetType="{x:Type Controls:LabeledDatePickerControl}"
4         <Setter Property="Validation.ErrorTemplate" Value="{StaticResource LabeledValidationTemplate}"/> 
5         <Setter Property="Width" Value="300"/> 
6         <Setter Property="Height" Value="24"/> 
7         <Setter Property="Margin" Value="8,8,8,0"/> 
8         <Setter Property="HorizontalAlignment" Value="Left"/> 
9         <Setter Property="VerticalAlignment" Value="Center"/> 
10         <Setter Property="VerticalContentAlignment" Value="Center"/> 
11         <Setter Property="SnapsToDevicePixels" Value="True"/> 
12         <Setter Property="FontFamily" Value="Verdana"/> 
13         <Setter Property="FontSize" Value="9"/> 
14         <Setter Property="FontWeight" Value="Bold"/> 
15         <Setter Property="Foreground" Value="{StaticResource ControlForegroundBrush}"/> 
16  
17         <Setter Property="Template"
18             <Setter.Value> 
19  
20                 <ControlTemplate TargetType="Controls:LabeledDatePickerControl"
21                     <Grid> 
22                         <Grid.ColumnDefinitions> 
23                             <ColumnDefinition Width="20"/> 
24                             <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:LabeledDatePickerControl}}, Path=LabelWidth}"/> 
25                             <ColumnDefinition Width="*"/> 
26                         </Grid.ColumnDefinitions> 
27  
28                         <TextBlock x:Name="MandatoryIndicatorControl" 
29                                    Foreground="{StaticResource MandatoryIndicatorForegroundBrush}" 
30                                    VerticalAlignment="Center" 
31                                    TextBlock.FontWeight="Bold" 
32                                    Grid.Column="0" 
33                                    Text="*" 
34                                    Visibility="Hidden" 
35                                    /> 
36  
37                         <TextBlock  Grid.Column="1" 
38                                     VerticalAlignment="Center" 
39                                     Foreground="{StaticResource LabelForegroundBrush}" 
40                                     Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:LabeledDatePickerControl}}, Path=LabelText}" 
41                                     /> 
42  
43                         <toolkit:DatePicker x:Name="DtPicker" 
44                                             Height="24" Grid.Column="2" 
45                                             Foreground="{StaticResource ControlForegroundBrush}" 
46                                             Background="{StaticResource ControlBackgroundBrush}" 
47                                             BorderBrush="{StaticResource ControlBorderBrush}" 
48                                             VerticalAlignment="Bottom" 
49                                             VerticalContentAlignment="Center" 
50                                             FontFamily="Verdana" FontSize="10" /> 
51  
52                     </Grid> 
53  
54                     <ControlTemplate.Triggers> 
55                         <Trigger Property="IsEnabled" Value="False"
56                             <Setter TargetName="DtPicker" Property="Background" 
57                                     Value="{StaticResource DisabledBackgroundBrush}" /> 
58                             <!--<Setter TargetName="DtPicker" Property="IsEnabled" 
59                                     Value="False" />--> 
60                             <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/> 
61                         </Trigger> 
62  
63                         <Trigger Property="Validation.HasError" Value="True"
64                             <Setter Property="ToolTip" 
65                                     Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}"/> 
66                         </Trigger> 
67  
68                         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMandatory}" 
69                                      Value="True"
70                             <Setter TargetName="MandatoryIndicatorControl" Property="Visibility" Value="Visible"/> 
71                         </DataTrigger> 
72  
73                     </ControlTemplate.Triggers> 
74                 </ControlTemplate> 
75  
76             </Setter.Value> 
77         </Setter> 
78     </Style> 

And the code from file LabeledDatePickerControl.cs

1 using System; 
2 using System.Windows; 
3 //using System.Windows.Data; 
4 using Microsoft.Windows.Controls; 
5  
6 namespace FBL.Registre.Core.UI.Controls 
7
8     public class LabeledDatePickerControl : DatePicker 
9     { 
10         public static readonly DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText"typeof(string), typeof(LabeledDatePickerControl), new PropertyMetadata("")); 
11         public static readonly DependencyProperty LabelWidthProperty = DependencyProperty.Register("LabelWidth"typeof(string), typeof(LabeledDatePickerControl), new PropertyMetadata("100")); 
12         public static readonly DependencyProperty IsMandatoryProperty = DependencyProperty.Register("IsMandatory"typeof(Boolean), typeof(LabeledDatePickerControl), new PropertyMetadata(false)); 
13         public static readonly DependencyProperty ValidationMarginProperty = DependencyProperty.Register("ValidationMargin"typeof(string), typeof(LabeledDatePickerControl), new PropertyMetadata("60,0,0,0")); 
14  
15         static LabeledDatePickerControl() 
16         { 
17             DefaultStyleKeyProperty.OverrideMetadata(typeof(LabeledDatePickerControl), new FrameworkPropertyMetadata(typeof(LabeledDatePickerControl))); 
18         } 
19  
20         public string LabelText 
21         { 
22             get { return (string)GetValue(LabelTextProperty); } 
23             set { SetValue(LabelTextProperty, value); } 
24         } 
25  
26         public string LabelWidth 
27         { 
28             get { return (string)GetValue(LabelWidthProperty); } 
29             set { SetValue(LabelWidthProperty, value); } 
30         } 
31  
32         public Boolean IsMandatory 
33         { 
34             get { return (Boolean)GetValue(IsMandatoryProperty); } 
35             set { SetValue(IsMandatoryProperty, value); } 
36         } 
37  
38         public string ValidationMargin 
39         { 
40             get { return (string)GetValue(ValidationMarginProperty); } 
41             set { SetValue(ValidationMarginProperty, value); } 
42         } 
43  
44         public string CheckValidation() 
45         { 
46             string validationMessage = ""
47  
48             if (IsMandatory) 
49             { 
50                 if (SelectedDate == null
51                     validationMessage += LabelText + " champ obligatoire."
52             } 
53  
54             return validationMessage; 
55         } 
56     } 
57

In the xaml page, I've this :

1 <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
2              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
3              xmlns:d="http://schemas.microsoft.com/expression/blend/2006" 
4              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" 
5              xmlns:Controls="clr-namespace:FBL.Registre.Core.UI.Controls;assembly=FBL.Registre.Core.UI.Controls" 
6              xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
7              x:Class="FBL.Registre.Processing.UI.StatsMS" 
8              > 
9  
10     <StackPanel> 
11  
12         <Controls:LabelControl  x:Name="errorLabel" 
13                                 HorizontalAlignment="Right" VerticalAlignment="Top" 
14                                 Width="800" MaxHeight="50" 
15                                 Content="" Foreground="Red" Margin="0,8,0,0" 
16                                 TextBlock.TextAlignment="Right" 
17                                 Block.TextAlignment="Right" /> 
18  
19         <Controls:LabelControl x:Name="ConfirmStart" 
20                                HorizontalAlignment="Left"  VerticalAlignment="Top" 
21                                Content="Remplissez les valeurs et Cliquez sur 'SUIVANT' pour démarrer l'envoi des statistiques" /> 
22  
23         <Controls:LabeledDatePickerControl x:Name="DateDeb" 
24                                            LabelText="Date de début de recherche : " 
25                                            Width="350" 
26                                            SelectedDateChanged="Date_SelectedDateChanged" 
27                                            LabelWidth="150" /> 
28         <Controls:LabeledDatePickerControl x:Name="DateFin" 
29                                            LabelText="Date de fin de recherche : " 
30                                            Width="350" 
31                                            SelectedDateChanged="Date_SelectedDateChanged" 
32                                            LabelWidth="150" /> 
33  
34         <Controls:LabeledComboBoxControl x:Name="typeRech" 
35                                          LabelText="Type de recherche :" 
36                                          HorizontalAlignment="Left" 
37                                          Width="350" 
38                                          SelectionChanged="typeRech_SelectionChanged" 
39                                          LabelWidth="150" /> 
40  
41         <toolkit:DatePicker x:Name="Test"></toolkit:DatePicker> 
42          
43         <Controls:TextBlockControl x:Name="InfosLabel" 
44                                    HorizontalAlignment="Center" 
45                                    VerticalAlignment="Top" Text="" 
46                                    TextWrapping="Wrap" Width="800" Height="250" 
47                                    Margin="10,20,0,0" /> 
48          
49         <Controls:ProgressBarControl x:Name="progressBar" 
50                                      HorizontalAlignment="Center" 
51                                      VerticalAlignment="Top" 
52                                      ProgressBarWidth="180" 
53                                      Margin="0,20,0,0"/> 
54          
55     </StackPanel> 
56      
57 </UserControl> 

In the control "Test", the selectedDate is ok, but in the other controls (DateDeb, DateFin), the selectedDate is always null

Is that someone can help me ?

Thanks in advance.