This is a migrated thread and some comments may be shown as answers.

Calendar and BusyIndicator

3 Answers 44 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 04 Aug 2011, 02:36 PM

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.

3 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 05 Aug 2011, 01:05 PM
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 >>
0
Chad
Top achievements
Rank 1
answered on 05 Aug 2011, 02:26 PM
So there is no way to tell the calendar to make selection changes on mouse up instead of mouse move?
0
Konstantina
Telerik team
answered on 11 Aug 2011, 12:16 PM
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 >>
Tags
Calendar
Asked by
Chad
Top achievements
Rank 1
Answers by
Pana
Telerik team
Chad
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or