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

Binding template to custom objects / multiple values

3 Answers 63 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kasper Schou
Top achievements
Rank 1
Kasper Schou asked on 25 Jan 2011, 12:35 PM
Hi,

I'm trying to achieve several customization on a single calendarbuttonitem (date) according to a series of date attributes, i.e.:

1. Holidays should have a colored background
2. Wednesdays should be bolded

Now I can achieve this easily using the DayTemplateSelector for each of the above separately by checking for wednesdays and returning a "wednesdayTemplate" that bolds the text, and for holidays returning a "holidayTemplate" that sets the background color.

But what if the date is both a wednesday and a holiday, I would like to add both styles. The real case is much more complicated, hence I can't accept simply creating a third template combining the styles.

What I really need is having only one template that are capable of binding to multiple values. It would be sufficient if I somehow could build the template in code behind rather that binding it in XAML, i.e. accessing the template setting backgroundcolor and font.

Is this possible, and what would be the recommended approach?

Thanks in advance!

Best regards,
Kasper Schou 

3 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 27 Jan 2011, 10:03 AM
Hello Kasper Schou,

Creating a third template/style for the CalendarButton is the most suitable solution for your case.

Regards,
Kaloyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kasper Schou
Top achievements
Rank 1
answered on 27 Jan 2011, 11:20 AM
Hi and thank you for the reply

Unfortunatly this is not a very desirable solution, since the example I gave is much simpler that what I'm trying to accomplish. I have up to 10 concurrent markings, so this would make 10 * 9 * 8 * 7 * 6 etc. combinations = ALOT templates.

Is there no way to affect the layout in code behind? In this case I don't care for view patterns, so if it would be possible to simply set the forecolor etc. of the CalendarButton in code behind when validated the date.

Something like:

 

 

if (content != null && content.ButtonType == CalendarButtonType.Date)

 

{

 

 

if(holidays.Contains(content.Date))

 

{

 

 

// Here I would like to access the layout, i.e. Forecolor
// xxx.Forecolor = Color.Blue

 

}

}

0
Kaloyan
Telerik team
answered on 31 Jan 2011, 01:49 PM
Hello Kasper Schou,

Attached is a possible solution for your case. It uses a custom CalendarButtonStyle that is changing its background according to the calendar button content.

Regards,
Kaloyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Calendar
Asked by
Kasper Schou
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Kasper Schou
Top achievements
Rank 1
Share this question
or