Tooltip Not Updating When Resources Change

2 posts, 1 answers
  1. Michael
    Michael avatar
    21 posts
    Member since:
    Apr 2011

    Posted 18 May 2011 Link to this post

    In ScheduleView I use a Tooltip template with a couple of converters to show the “Staff” and “Company” resources when someone hovers over the appointment.

    If I update the Resource in the appointment the tooltip still shows the original resource not the new value, the converter doesn’t get triggered.

    I assume this is a binding problem with the Appointment.Resources collection?

    Is this by design? If so is there a workaround?

    Tooltip: 

    <DataTemplate x:Key="ToolTipTemplate">
          <StackPanel>
              <TextBlock FontWeight="Bold" FontSize="12" Text="{Binding Appointment.Subject}"/>
              <TextBlock Text="{Binding Category, Mode=OneWay, Converter={StaticResource ScheduleCategoryConverter}}"/>
              <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Staff: "/>
                  <TextBlock Text="{Binding Appointment.Resources, Mode=OneWay, Converter={StaticResource ScheduleResourceStaffConverter}}"/>
              </StackPanel>
              <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Company: "/>
                  <TextBlock Text="{Binding Appointment.Resources, Mode=OneWay, Converter={StaticResource ScheduleResourceCompanyConverter}}"/>
              </StackPanel>
              <StackPanel Orientation="Horizontal">
                  <TextBlock Text="{Binding Appointment.Start, Mode=OneWay, StringFormat=h:mm tt}"/>
                  <TextBlock Text=" - "/>
                  <TextBlock Text="{Binding Appointment.End, Mode=OneWay, StringFormat=h:mm tt}"/>
              </StackPanel>
          </StackPanel>
      </DataTemplate>

    Converter:

     

    public class ScheduleResourceCompanyConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              string strToRet = "None";
              if (value != null)
              {
                  ResourceCollection Res = (ResourceCollection)value;
                  foreach (Resource res in Res)
                  {
                      if (res.ResourceType == "Company") strToRet = res.DisplayName;
                  }
              }
              return strToRet;
          }
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              return null;
          }
      }

  2. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 20 May 2011 Link to this post

    Hello Michael,

    When you bind to Appointment.Resources the binding will change only when Appointment raise PropertyChanged event for Resources property. But this never happens because Resources is collection property and is read only (e.g. standard pattern for implementing ICollection properties).

    One possible solution is to change the TextBlock to ItemsControl and bind ItemsSource to Appointment.Resources and then to specify ItemTemplate and use converters.

    Another approach will be to extend the Appointment class and add handler to Resources CollectionChanged event and when CollectionChanged is fired to raise PropertyChanged with Resource property.

    I hope that this will help you.

    All the best,
    Hristo
    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 banner
Back to Top