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

[Solved] DatePicker Background does not look proper when set from code behind.

3 Answers 133 Views
DatePicker for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Simon
Top achievements
Rank 1
Simon asked on 07 Nov 2013, 07:12 PM
The DatePicker Background comes out looking fine when using named brushes, but when setting in codebehind or using styles in codebehind it does not look correct.  Please see attached file screenshots.


1. DatePicker background set using named brushes, looks fine.
<SolidColorBrush x:Key="TelerikDateTimePickerBackgroundBrush" Color="Red" />
<SolidColorBrush x:Key="TelerikDateTimePickerForegroundBrush" Color="Black" />
<SolidColorBrush x:Key="TelerikDateTimePickerBorderBrush" Color="Red" />


2. DatePicker background set using code behind does not look good. (Comes out with a bit of red in the back, but mostly pink)
datePicker = new RadDatePicker();
datePicker.Background = new SolidColorBrush(Colors.Red);



3. DatePicker background set using styles in code behind does not look good. (Comes out with a bit of red in the back, but mostly pink)

Style dateTimePickerButtonStyle = new Style();
dateTimePickerButtonStyle.TargetType = typeof(DateTimePickerButton);        
 
dateTimePickerButtonStyle.Setters.Add(new Setter() { Property = DateTimePickerButton.FontSizeProperty, Value = base.FontSize() });
dateTimePickerButtonStyle.Setters.Add(new Setter() { Property = DateTimePickerButton.BackgroundProperty, Value = new SolidColorBrush(backgroundColor) });
 
datePicker.Resources.Add(typeof(DateTimePickerButton), dateTimePickerButtonStyle);

3 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 11 Nov 2013, 12:51 PM

Hello Simon,

Thank you for your question.

To change the appearance of the picker button you have to add a Style that targets the DateTimePickerButton class in the Resources dictionary of the RadDatePicker control. In code behind this would look like this:

var datePicker = new RadDatePicker();
datePicker.BorderBrush = new SolidColorBrush(Colors.Red);
Style style = new Style(typeof(DateTimePickerButton));
style.Setters.Add(new Setter(DateTimePickerButton.BackgroundProperty, new SolidColorBrush(Colors.Red)));
style.Setters.Add(new Setter(DateTimePickerButton.ForegroundProperty, new SolidColorBrush(Colors.Black)));
datePicker.Resources.Add(new KeyValuePair<object, object>(typeof(DateTimePickerButton), style));

I hope this was useful. Please, do not hesitate to contact us if you have further questions.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Simon
Top achievements
Rank 1
answered on 11 Nov 2013, 04:18 PM
Yes your example is exactly what I have been doing, (see my 3rd code example in original post).

My issue is how the date picker looks once you apply the background changes.  If you do it via the named brushes it comes out fine, if you do it in codebehind either via the background property or via the DateTimePickerButton style, it comes out improper.  Please see attached screenshots in original post.

Thanks
Simon
 
0
Rosy Topchiyska
Telerik team
answered on 11 Nov 2013, 05:32 PM
Hello Simon,

Sorry for misleading you. 

The Background property of the RadDatePicker is not meant to change the background as you would expect and if you set it, you will get the datepicker-background-bad.gif result. The right way to change the background is either by the Telerik named brushes, or via a Style as in your third example. Both ways work fine on our side. I have attached a sample project that uses the code from your third example. Could you clarify if it looks good if you run it, and if yes, please modify it in order to reproduce the issue. 

I look forward to your reply. 

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DatePicker for XAML
Asked by
Simon
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Simon
Top achievements
Rank 1
Share this question
or