Binding template to custom objects / multiple values

4 posts, 0 answers
  1. Kasper Schou
    Kasper Schou avatar
    6 posts
    Member since:
    May 2010

    Posted 25 Jan 2011 Link to this post

    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 
  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 27 Jan 2011 Link to this post

    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>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kasper Schou
    Kasper Schou avatar
    6 posts
    Member since:
    May 2010

    Posted 27 Jan 2011 Link to this post

    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

     

    }

    }

  5. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 31 Jan 2011 Link to this post

    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>>
Back to Top