Calendar and BusyIndicator

4 posts, 0 answers
  1. Chad
    Chad avatar
    10 posts
    Member since:
    Oct 2010

    Posted 04 Aug 2011 Link to this post

    I'm having a problem with the selected dates automatically changing inside of the calendar just by moving the mouse over the calendar.

    To reproduce, put the calendar inside of a busyindicator:

    <telerik:RadBusyIndicator x:Name="busyIndicator">
        <telerik:RadCalendar SelectionMode="Extended"
            SelectionChanged="calendar_SelectionChanged"
            x:Name="calendar">
        </telerik:RadCalendar>
    </telerik:RadBusyIndicator>

    In the code behind, simulate an async call and set IsBusy to true while the call takes place:

    private void calendar_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        busyIndicator.IsBusy = true;
      
        BackgroundWorker bw = new BackgroundWorker();
        bw.DoWork += (o, x) =>
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
      
                for (int i = 0; i < 999999; i++)
                    sb.AppendLine(i.ToString());
      
                Dispatcher.BeginInvoke(() =>
                {
                    busyIndicator.IsBusy = false;
                });
            };
        bw.RunWorkerAsync();
    }

    Run the code and click on a date in the calendar while moving the mouse in circles over the calendar.  After about the third click, the calendar will automatically start selecting dates without having to click the mouse.  Its an endless cycle of the busy indicator being toggled on and off and dates on the calendar changing without clicking the mouse.
  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 05 Aug 2011 Link to this post

    Hi Chad,

    You've missed the point where the selection changed is dispatched more than once. For the RadCalendar it would be invoked once to remove the old selected days and once to add the newly selected days. This would start two background workers and when the first completes the second will still work. Clicking will select dates and start new background workers setting is busy to true while completing dispatchers will set IsBusy to false allowing for more selection changes on mouse events this will go on and on.

    The following code will make the process a little bit better:
    private int workersCount = 0;
    private void calendar_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        workersCount++;
        busyIndicator.IsBusy = workersCount > 0;
        BackgroundWorker bw = new BackgroundWorker();
        bw.DoWork += (o, x) =>
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < 999999; i++)
                sb.AppendLine(i.ToString());
            Dispatcher.BeginInvoke(() =>
            {
                workersCount--;
                busyIndicator.IsBusy = workersCount > 0;
            });
        };
        bw.RunWorkerAsync();
    }
     
    However the at some point the RadCalendar will miss the mouse up event while disabled (If you release the mouse while its busy) and will begin changing selection upon mouse move events clicking without moving the mouse over the calendar will stop the selection changes. Now thats a bug that can not be easily workarounded. I could only suggest you to put the RadCalendar outside the RadBusyIndicator.

    Kind regards,
    Pana
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. DevCraft banner
  4. Chad
    Chad avatar
    10 posts
    Member since:
    Oct 2010

    Posted 05 Aug 2011 Link to this post

    So there is no way to tell the calendar to make selection changes on mouse up instead of mouse move?
  5. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 11 Aug 2011 Link to this post

    Hello Chad,

    I am afraid there is no way to change the event on which the SelectionChanged is hooking, as it is hard coded in the source code.

    Kind regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Back to Top