Change the color of individual appointments

7 posts, 0 answers
  1. Tyler
    Tyler avatar
    32 posts
    Member since:
    Jun 2011

    Posted 12 Aug 2011 Link to this post

    If there are multiple appointments for a single day, is it possible to have each appointment display as a different color?

    I have this right now, but "DetailText" seems to be all appointments concatenated together.

    <telerikInput:RadCalendar.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="5">
                                    <StackPanel Background="{Binding CANCELLATION_ID, Converter={StaticResource CancelledColorConverter} }">
                                        <TextBlock Text="{Binding DetailText}" Foreground="Red"  FontSize="7" MaxHeight="25" VerticalAlignment="Top" Margin="0,-2,0,0"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding Text}" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                                </Grid>
                            </DataTemplate>
                        </telerikInput:RadCalendar.ItemTemplate>
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 18 Aug 2011 Link to this post

    Hello Tyler,

    Sorry for the late reply - there is a new property available in the CalendarButtonContentInfo class called Appointments. You can use it in your data template with a converter to style each appointment.

    Best wishes, Valentin.Stoychev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Tyler
    Tyler avatar
    32 posts
    Member since:
    Jun 2011

    Posted 22 Aug 2011 Link to this post

    Could you provide some more details on how to use ItemTemplateSelector and Appointments to color each appointment for a day differently.  I've seen the Special days sample but I still seem to be missing something.  

    Do I need updated binaries for this?  

    I'm currently on 2011.2.712.1037
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 25 Aug 2011 Link to this post

    Hi Tyler,

     Thank you for writing.
    In order to achieve different colors for different appointments you must define a custom item template that contains as many TextBlock objects as there are appointments for a certain day. Since the number of appointments will vary from day to day you have have to determine what is the maximum number of appointments that you want to display and create the template with this many TextBlock objects.

    After the template is ready, you have to bind the text blocks' Text and Foreground properties to the DetailText property of the view model that the your custom ItemTemplate binds to. The trick here is that the view model's DetailText property contains all appointments concatenated in a single string delimited by new lines. You somehow have to split that string into individual appointments and bind each text block to the correct appointment. Fortunately this can easily be done with a custom binding converter.

    Another subtle thing is that the Foreground property of the text blocks is bound a property of type string. Again, a custom binding converter must be used and with this converter you will be able to define a custom color for each appointment.

    Please have a look at the sample application that I prepared (see attachment). It contains a basic implementation of the description above.

    Please write again if you have other questions.

    Best wishes,
    Victor
    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 >>

  6. Brian Pautsch
    Brian Pautsch avatar
    15 posts
    Member since:
    Jun 2009

    Posted 12 Dec 2011 Link to this post

    I understand your example, but you would never color text based on the appointment subject (which is what the DetailText really is). Why aren't other properties available, including custom ones? Minimally, there should be a Key or ID field available so we could make decisions.

    In my scenario, we have different appointment types which have different colors. I need to be able to show a little text and color code it based on the appropriate color (which is another property of the "SampleAppointment" class). How would you accomplish this?

    Thanks in advance,
    Brian
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 13 Dec 2011 Link to this post

    Hello Brian Pautsch,

    You are right that it will be good to introduce a custom property for this scenario. How it is sounds to have a Tag called property of type object as part of the IAppointment interface? Will this fit your scenario?

    Kind regards, Valentin.Stoychev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Brian Pautsch
    Brian Pautsch avatar
    15 posts
    Member since:
    Jun 2009

    Posted 13 Dec 2011 Link to this post

    I think the Tag property is a great idea. Please see my other forum issue (related to this forum). Without the Tag property, I'm using the Subject to string together values and then using a Converter to parse them. Please implement that.
Back to Top
DevCraft banner