Binding the AppointmentBackground

4 posts, 0 answers
  1. Jakkie Esschert van den
    Jakkie Esschert van den avatar
    61 posts
    Member since:
    Sep 2009

    Posted 07 Apr 2011 Link to this post


    I'm trying to Dynamically bind the background color of an Appointment, so it changes based on data in my model. However, I can't get it to update properly when the data in my model changes. Changing the AppointmentContentTemplate doesn't allow me to set the set the entire background, so I guess it has to be done through a Style. I have a working style which set the background correctly, however in Silverlight it seems I can't bind to a Setter. Therefore I cant use a Style binds to my Model, I wrote a custom style selector which selects a style based on the Model data. This works correctly, but doesn't update instantly when the Appointment changes. When I change the Appointment, the background isn't changed until I switch between views. 

    Does anyone know how I can make the background color react to changes in my model instantly?

  2. Dani
    Dani avatar
    848 posts

    Posted 12 Apr 2011 Link to this post

    Hello Jakkie,

    Generally you would use a StyleSelector to apply different styling to appointments based on some custom logic that you wish to have. However, the style selector sets the style once, and from this point on it is not aware that an appointment changes until you switch between views (appointments get recreated then).

    So I would suggest that you use a custom  AppointmentContentTemplate that has an additional element  - a Border for example, and the background property of this element will be data bound to a property from your view model (most likely through a Converter).

    Consider the following template:
    <DataTemplate x:Key="MyAppointmentContentTemplate">
                   <Border Background="{Binding MyProperty, Converter={StaticResource MyPropertyToBackgroundConverter}}"/>
                   <TextBlock Text="{Binding}" />

    Let me know if this solution works well for you.

    Kind regards,
    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
  3. DevCraft R3 2016 release webinar banner
  4. Forest
    Forest avatar
    72 posts
    Member since:
    Aug 2010

    Posted 14 Oct 2011 Link to this post

    I've tried this solution. It works.
    But there is still a small problem.

    How can we also change the color of the "Time-markers" place ?  (on the left side of the appointment)

    This place has still a white color.

    Thank you
  5. Dani
    Dani avatar
    848 posts

    Posted 17 Oct 2011 Link to this post

    Hello Forest,

    The solution uses a ContentTemplate for the appointment item, but the white space gap is rather part of the ControlTemplate of the appointment. And the content of the appointment stretches exactly where the light blue color from your screenshot appears.

    One option is to use negative margins and try to overlap the gap on the left. However, if you ever use time markers on these appointments, they will be overlapped by your new background. Unless you use semitransparent color.

    Another thing you can do is to modify the control template of the appointment so that the content stretches across the entire rectangle and then your content template will take care of the background change.

    I hope this will be helpful.

    Best wishes,
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top