Change day button background

13 posts, 0 answers
  1. Andrew
    Andrew avatar
    27 posts
    Member since:
    Nov 2008

    Posted 04 Jan 2010 Link to this post

    How can I change the background colour of the day buttons in code? I can see how to change the 'special day' foreground text colour but I want to change the background colour of the whole button not just the text. I'm guessing it has something to do with changing the button style but I cannot work out how to alter the style in code.

    Andrew
  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 05 Jan 2010 Link to this post

    Hi Andrew,

    You have to define your own DayButtonStyle or DayButtonStyleSelector to achieve the desired result. Attached is a sample app, that might help you in resolving your case.

    All the best,
    Kaloyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Ulrich Fiege
    Ulrich  Fiege avatar
    62 posts
    Member since:
    Sep 2005

    Posted 14 Jul 2010 Link to this post

    Hello, i also need to change the backcolor from the day buttons.
    I try'd to run this sample but with no success using current version Q1,SP2/0712.
    Is it possible to set backgound color in other simple way without huge templates?
    greetings ... 
     
  5. soporte pasiona
    soporte pasiona avatar
    2 posts
    Member since:
    Oct 2009

    Posted 15 Jul 2010 Link to this post

    I also have the same issue with this sample, the current Silverlight RADControls (version 2010.2.714.1040) do not fire the SelectStyle event.

  6. Pana
    Admin
    Pana avatar
    748 posts

    Posted 19 Jul 2010 Link to this post

    Hello,

    Ulrich, there is no easier way than creating a selector.

    Soprote, can you send some example code you are using. The selector should work. We even have some examples that customize the different days in our examples for the calendar.

    Greetings,
    Panayot
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Ulrich Fiege
    Ulrich  Fiege avatar
    62 posts
    Member since:
    Sep 2005

    Posted 21 Jul 2010 Link to this post


    Thank you for your answer, but i have no code and i look how to slove this.
    I need to change the background-color from some defined dates in code behind.
    Here is some code from ASP.net using also telerik calendar what we try to translate into silverlight.
    If EventList Is Nothing = False Then
               Dim objExistingDates As New List(Of Telerik.Web.UI.RadCalendarDay)
               For i As Integer = 0 To EventList.Length - 1
                   Dim SD As New Telerik.Web.UI.RadCalendarDay
                   SD.Date = EventList(i).eventTime
                   SD.ItemStyle.BackColor = Drawing.Color.Orange
                   objExistingDates.Add(SD)
               Next i
               cDateTo.SpecialDays.AddRange(objExistingDates.ToArray)
           End If
    In this case we define a special color to a range of dates in code behind.
    How can we do this in Silverlight using radcalendar?
    Thank you and greetings ...

  8. Pana
    Admin
    Pana avatar
    748 posts

    Posted 23 Jul 2010 Link to this post

    Hi Ulrich Fiege,

    I am attaching a project that displays how this change can be done in Silverlight. It uses a simple StyleSelector that will alter the day buttons. The present CalendarButton ControlTemplate does not implement TemplateBindings for Background, Foreground and BorderThickness. We will make sure to have this fixed in one of our internal builds.

    All the best,
    Panayot
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Ulrich Fiege
    Ulrich  Fiege avatar
    62 posts
    Member since:
    Sep 2005

    Posted 25 Jul 2010 Link to this post

    Thank you for the example. I have the problem to set the dates from code manually like in my sample above and not automaticly
    like in this sample from the app.cs. Can you give me please a hint to slove this issue.
    Thank you ... and greetings ...
  10. Pana
    Admin
    Pana avatar
    748 posts

    Posted 26 Jul 2010 Link to this post

    Hello Ulrich,

    You want to change the dates from code like change the month the calendar is displaying or change the content of each button from code behind? Can you give me more information what you are trying to achieve or perhaps attach a small screenshot with the desired look of the calendar and what you want to modify in code?

    Regards,
    Panayot
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Bo Kristensen
    Bo Kristensen avatar
    2 posts
    Member since:
    Dec 2004

    Posted 27 Jul 2010 Link to this post

    I would like to change background on specific dates programmaticly. So what I want to accomplish is a property eg. radCalendar.DifferentStyledDates that works more or less the same as radCalendar.SelectedDates.

    Your example only shows how to change for the entire calendar and it is not changeable on events from other ui controls.

    Is that possible?
  12. Pana
    Admin
    Pana avatar
    748 posts

    Posted 29 Jul 2010 Link to this post

    Hi Bo Kristensen,

    This behavior is not supported out-of-the-box. You can extend the RadCalendar and create additional collection that will keep these custom dates and an attached behavior that you can use to set the background of the buttons. The behavior should do something like parent-of-type to find the RadCalendar and then listen for changes to your collection. When it changes the behavior should update the button's background. This solution is as hard as building your own new control.

    Best wishes,
    Panayot
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Scott
    Scott avatar
    66 posts
    Member since:
    Nov 2009

    Posted 23 Aug 2011 Link to this post

    Is there a better way to change the backgound of a day with a newer release or should I still use the technique in the radcalendar-custmobackgrounds.zip example?
  14. Dani
    Admin
    Dani avatar
    848 posts

    Posted 29 Aug 2011 Link to this post

    Hello Scott,

    The RadCalendar control does not bear significant changes since 2010 Q2. Please, use the approach suggested in the sample. You can just clean up the xaml a little bit: remove the CalendarButtonStyle from MainPage. It was added for the purpose of taking advantage of TemplateBindings. These TemplateBindings are currently implemented in the template of RadCalendar, so the style is not needed anymore.

    <UserControl.Resources>
            <local:CalendarButtonStyleSelector x:Key="StyleSelector">
               <local:CalendarButtonStyleSelector.EvenStyle>
                   <Style TargetType="calendar:CalendarButton">
                       <Setter Property="Background" Value="Red" />
                   </Style>
               </local:CalendarButtonStyleSelector.EvenStyle>
               <local:CalendarButtonStyleSelector.OddStyle>
                   <Style TargetType="calendar:CalendarButton">
                       <Setter Property="Background" Value="Green" />
                   </Style>
               </local:CalendarButtonStyleSelector.OddStyle>
           </local:CalendarButtonStyleSelector>      
       </UserControl.Resources>
         
       <Grid x:Name="LayoutRoot" Background="White">        
           <telerik:RadCalendar DayButtonStyleSelector="{StaticResource StyleSelector}" DayButtonStyle="{x:Null}" Margin="8,34,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
       </Grid>

    I hope this helps.

    Regards,
    Dani
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
DevCraft banner