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

Change the color of individual appointments

6 Answers 122 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tyler
Top achievements
Rank 1
Tyler asked on 12 Aug 2011, 06:39 AM
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>

6 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 18 Aug 2011, 08:00 AM
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 >>

0
Tyler
Top achievements
Rank 1
answered on 22 Aug 2011, 05:11 PM
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
0
Victor
Telerik team
answered on 25 Aug 2011, 12:12 PM
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 >>

0
Chris Pautsch
Top achievements
Rank 1
answered on 12 Dec 2011, 09:18 PM
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
0
Valentin.Stoychev
Telerik team
answered on 13 Dec 2011, 07:50 AM
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 >>

0
Chris Pautsch
Top achievements
Rank 1
answered on 13 Dec 2011, 03:43 PM
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.
Tags
Calendar
Asked by
Tyler
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Tyler
Top achievements
Rank 1
Victor
Telerik team
Chris Pautsch
Top achievements
Rank 1
Share this question
or