Data trigger not working with dynamically created date picker

3 posts, 1 answers
  1. akjoshi
    akjoshi avatar
    26 posts
    Member since:
    Nov 2008

    Posted 19 Dec 2008 Link to this post

    I am creating a date picker in my code and want to change its background whenever its value is not valid(specified by IsValidFieldValue flag), but its not working .

    Here is my code for creating the control and style :

    // Binding to be set for control 
    Binding binding = new Binding("Value"); 
    binding.Mode = BindingMode.TwoWay; 
    binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; 
    string datePickerXamlTemplate = "<telerik:RadDatePicker x:Name=\"uxDatePickerCustomField{0}\" Grid.Row=\"1\" Grid.Column=\"1\" Height=\"24\" HorizontalAlignment=\"Left\" Margin=\"8,5,8,5\" Width=\"125\" xmlns=\"\" xmlns:telerik=\"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input\" xmlns:x=\"\" />"; 
    string datePickerXaml = string.Format(datePickerXamlTemplate, field.Id, count); 
    stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(datePickerXaml)); 
    RadDatePicker datePicker = (RadDatePicker)System.Windows.Markup.XamlReader.Load(stream); 
    datePicker.SetBinding(RadDatePicker.SelectedDateProperty, binding); 
    datePicker.Style = (Style)FindResource("DatePickerStyle"); 
    datePicker.DataContext = field; // Object having properties - Value and IsValidFieldValue. Implements INotifyPropertyChanged
    uxGrid.Children.Add(datePicker); // Added to a Grid  

            <Style TargetType="{x:Type telerikInput:RadDatePicker}" x:Key="DatePickerStyle"
                    <DataTrigger Binding="{Binding Path=IsValidFieldValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Value="false"
                        <Setter Property="telerikInput:RadDatePicker.Background" Value="#FFFFB9B9" /> 

  2. Answer
    Miroslav avatar
    922 posts

    Posted 23 Dec 2008 Link to this post

    Hello Abhishek,

    There was a bug in the ControlTemplate of the DatePicker that means that the Background was not applied.

    This will be fixed in the next ServicePack. I am attaching a project where I have included a fixed ControlTemplate in the App.xaml resources. You use this style until the release.

    I am sorry if this has been an issue for you.
    Thanks for your feedback!

    All the best,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. akjoshi
    akjoshi avatar
    26 posts
    Member since:
    Nov 2008

    Posted 24 Dec 2008 Link to this post

    Hi Miroslav,

    Thanks for the solution, will try this and let you know the result.

    Merry Xmas :)
Back to Top