Bug in Background color of appointment?

7 posts, 0 answers
  1. Francisco Bernardo
    Francisco Bernardo avatar
    22 posts
    Member since:
    Jul 2009

    Posted 24 May 2012 Link to this post

    Hello,

    I'm using ScheduleView in this scenario where I've extended the Appointment Class with my own custom class (ActivityWrapper 
    ). My class stores a brush as a property in order to establish a binding to the AppointmentItemBaseStyle Background property, and that way, to present the Appointments in the Schedule view with a controlled color range.

    The style

            <Style x:Key="AppointmentItemBaseStyle" TargetType="telerik_GeneralScheduleView:AppointmentItem">
                <Setter Property="Background" Value="{Binding Converter={StaticResource AppointmentToActivityWrapperColor}}" />
                <Setter Property="BorderBrush" Value="{StaticResource RadScheduleForeground}" />
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Stretch" />
                <Setter Property="Foreground" Value="Black" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="Padding" Value="2 0 0 0" />
                <Setter Property="ContentTemplate" Value="{StaticResource AppointmentItemTemplate}" />
                <Setter Property="Template" Value="{StaticResource AppointmentItemHorizontalControlTemplate}" />
                <Setter Property="Canvas.ZIndex" Value="1" />
            </Style>
    
    The converter
    
    

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
         {
             try
             {
                 AppointmentItemProxy aip = value as AppointmentItemProxy;
                 if (aip != null)
                 {
                     ActivityWrapper aw = ((ActivityWrapper)aip.Appointment);
                     if(aw.IsEnabled)
                         return aw.Color;
                     else
                         return new SolidColorBrush(Colors.LightGray);
                 }
                 else
                     return new SolidColorBrush(Colors.LightGray);
             }
             catch (Exception ex)
             {
                 LoggingManager.Error("Module.ActivitySet.Silverlight", "AptmColorToBackgroundConverter", "Convert", "General failure", ex);
                 return null;
             }
         }
    However, when I scroll in the schedule view, or edit some appointment, the colors of the Apppointments interchange erroneously- I believe there is some bug in the control, because the bounded objects keep their state. Can you acknowledge and provide any solution? Thank you, Francisco
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 28 May 2012 Link to this post

    Hello Francisco,

    This behavior results from the fact that the DataContext does not get updated. This is intended and is done for performance optimization.
     Your Converter is called only once. And so the appointments do not maintain the correct background color.

    The right thing to do is bind directly to your Brush property. If you have a Brush property in your custom appointment, you are able to bind directly to it without the need for a Converter. Please, check the following:
    <Style x:Key="AppointmentItemBaseStyle" TargetType="telerik:AppointmentItem">
                <Setter Property="Background" Value="{Binding Appointment.MyColor}" />
    </Style>

    I think the result from the above is the behavior you are looking for.

    I hope this helps.

    Regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Francisco Bernardo
    Francisco Bernardo avatar
    22 posts
    Member since:
    Jul 2009

    Posted 29 May 2012 Link to this post

    Hello Dani,

    thank you for replying. I have tried that solution already, but I didn't go forward with as I noticed that a NullExcepction appeared and crashed the application. I believe this happens because the appointment in Binding Appointment.MyColor comes up null, whenever you start messing with the scrollbar.

    Any alternative?

    Regards,
    Francisco 
     
  5. Dani
    Admin
    Dani avatar
    848 posts

    Posted 01 Jun 2012 Link to this post

    Hi Francisco,

    It is strange that you get a NullException... You can still try using your Converter as long as you set the Binding through the AppointmentItemProxy.Appointment property as this is what gets updated, and not the DataContext.

    I hope this will work fine in your scenario.

    Regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Michael MSTG
    Michael MSTG avatar
    46 posts
    Member since:
    Aug 2012

    Posted 30 Jan 2013 Link to this post

    I too have a schedule view instance that seemingly does not always apply a background color to the template.

    My XAML:
    <DataTemplate x:Key="AppointmentTemplate">
            <Grid Background="{Binding Path=Appointment.Background}">
                <TextBlock Text="{Binding Subject}"
                           TextWrapping="Wrap"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Top"
                           FontSize="11"
                           Foreground="{Binding Path=Appointment.TextForeground}" />
            </Grid>
        </DataTemplate>
     ...
    <telerik:RadScheduleView x:Name="svBusSchedule"
    AppointmentItemContentTemplate="{StaticResource AppointmentTemplate}"
    AllowDrop="False"
    IsInlineEditingEnabled="False"
    UseDefaultCursorsOnDrag="False"
    Height="400"
    toolkit:DockPanel.Dock="Top">
    </telerik:RadScheduleView>



    Snippet of the code to build the appointment:

    Dim appointment As New AdminDashboardRestrictedBusOrderAppointment()
            With appointment
     
    .TextForeground = New SolidColorBrush(Colors.White)
                If scheduleItem.IsReviewed.HasValue Then
                    If scheduleItem.IsReviewed.Value Then
                        If scheduleItem.IsFulfilled Then
                            .Background = New SolidColorBrush(Colors.Green)
                        Else
                            .Background = New SolidColorBrush(Color.FromArgb(255, 255, 165, 29))
                        End If
                    Else
                        If String.IsNullOrWhiteSpace(scheduleItem.ReviewedUserId) Then
                            .Background = New SolidColorBrush(Colors.Purple)
                        Else
                            .Background = New SolidColorBrush(Colors.Red)
                        End If
                    End If
                Else
                    If scheduleItem.IsFulfilled Then
                        .Background = New SolidColorBrush(Colors.Green)
                    Else
                        .Background = New SolidColorBrush(Color.FromArgb(255, 255, 165, 29))
                    End If
                End If
     
    End With


    Is there any reason that can be seen as to why the attached screen shot would result (intermittently at that)?  The issue appointments I've added arrows to.

    Mike
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 04 Feb 2013 Link to this post

    Hi Michael,

    I am not sure what could be the reason for this issue. Is it possible to send us a runnable project where we can observe the erroneous behavior? Thanks

    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Michael MSTG
    Michael MSTG avatar
    46 posts
    Member since:
    Aug 2012

    Posted 04 Feb 2013 Link to this post

    Unfortunately I don't believe I can devote that much time for a full runnable project at this point.  The code I submitted is part of the logic where the appointment is generated.  What I added was the logic that deals with the colors.  The appointments are data driven in that I use a query to pull "orders" from a table.  The "subject" property is simply pulling the order ID to display so the logic before the color area is devoted to how the ID is displayed.  You have all the XAML I have. 

    On the page init, this is what is run:
    Me.OrderAppointments= New ObservableAppointmentCollection()
            svBusSchedule.AppointmentsSource = Me.OrderAppointments
            svBusSchedule.IsInlineEditingEnabled = False

    The data source is set after the data is loaded (load callback):
    Private Sub OrderSchedule_Loaded(ByVal results As LoadOperation(Of ScheduleItem))
            Me.OrderResources = New Telerik.Windows.Controls.ResourceTypeCollection()
            Me.OrderAppointments.Clear() 'ObservableAppointmentCollection
     
            'resources for grouping
            Dim vehicleNames As IEnumerable(Of String) = results.Entities.Select(Function(b) b.VehicleTypeDescription).Distinct()
            Dim vehicleResourceType As New Telerik.Windows.Controls.ResourceType("VehicleTypeDescription")
            Me.OrderResources.Add(vehicleResourceType)
     
            For Each vehicleName As String In vehicleNames
                vehicleResourceType.Resources.Add(New Telerik.Windows.Controls.Resource(vehicleName))
            Next
            svBusSchedule.ResourceTypesSource = Me.OrderResources
     
            'appointments
            For Each si As ScheduleItem In results.Entities
                Dim scheduleItem As ScheduleItem = si
                Dim resource As Telerik.Windows.Controls.IResource = (From r As Telerik.Windows.Controls.IResource
                                                                      In vehicleResourceType.Resources
                                                                      Where r.ResourceName = scheduleItem.VehicleTypeDescription).First()
     
                GenerateAppointment(scheduleItem, resource))
            Next
        End Sub


    My problem has been that I have never seen this schedule viewer do this however I do not use it as much as the one user who presented the problem does.  If it is nothing obvious then I am at a loss.
Back to Top
DevCraft banner