Last Updated: 03 Sep 2018 06:38 by Dimitar
Created on: 30 Aug 2018 10:39
Category: Scheduler/Reminder
Type: Bug Report
FIX. RadScheduler - InvalidOperationException in the AppointmentElement class when trying to paint the recurrence icon in an application with multiple UI threads
Workaround: create a custom Appointment and override the PaintRecurrenceIcon method

Public Class MyAppointmentElement
    Inherits AppointmentElement

    Public Sub New(scheduler As RadScheduler, view As SchedulerView, appointment As IEvent)
        MyBase.New(scheduler, view, appointment)
    End Sub

    Public Overrides Sub PaintRecurrenceIcon(graphics As IGraphics)

        If Not Me.Recurring Then
        End If

        Dim icon As Image = DirectCast(GetType(AppointmentElement).GetMethod("GetRecurrenceIcon", BindingFlags.Instance Or BindingFlags.NonPublic).Invoke(Me, Nothing), Image)

        If icon Is Nothing Then
        End If

        SyncLock icon
            Dim clientRect As RectangleF = Me.GetClientRectangle(Me.Bounds.Size)
            Dim x As Integer = CInt(clientRect.X) + CInt(clientRect.Width) - icon.Width

            If Me.RightToLeft Then
                x = CInt(clientRect.X)
            End If

            Dim imageRect As Rectangle = New Rectangle(x, CInt(clientRect.Y) + CInt(clientRect.Height) - icon.Height, icon.Width, icon.Height)
            graphics.DrawImage(imageRect, icon, ContentAlignment.TopLeft, True)
        End SyncLock
    End Sub
End Class

Public Class MyElementProvider
    Inherits SchedulerElementProvider
    Public Sub New(scheduler As RadScheduler)
    End Sub
    Protected Overrides Function CreateElement(Of T As SchedulerVisualElement)(view As SchedulerView, context As Object) As T
        If GetType(T) = GetType(AppointmentElement) Then
            Return TryCast(New MyAppointmentElement(Me.Scheduler, view, DirectCast(context, IEvent)), T)
        End If
        Return MyBase.CreateElement(Of T)(view, context)
    End Function
End Class