This is a migrated thread and some comments may be shown as answers.

Data trigger not working with dynamically created date picker

2 Answers 319 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
akjoshi
Top achievements
Rank 1
akjoshi asked on 19 Dec 2008, 05:10 PM

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=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:telerik=\"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" />"; 
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  
 


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

2 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 23 Dec 2008, 02:48 PM
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,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
akjoshi
Top achievements
Rank 1
answered on 24 Dec 2008, 12:13 PM
Hi Miroslav,

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

Merry Xmas :)
Tags
DatePicker
Asked by
akjoshi
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
akjoshi
Top achievements
Rank 1
Share this question
or