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

Changing default values on recurrence object

3 Answers 110 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
hwsoderlund
Top achievements
Rank 1
hwsoderlund asked on 24 Jan 2011, 06:58 PM
In our system we have decided not to allow unlimited recurrence for appointments. I can easily modify the EditRecurrenceTemplate to just hide the radio button for that option, but I cannot find a good way of setting the default value on the underlying RecurrenceDialogViewModel when it is loaded. I came up with a behaviour that I attached to the root grid of the EditRecurrenceTemplate (the code is pasted below in case anybody else needs this). By listening to the Loaded event of the grid, I can catch the RecurrenceDialogViewModel and change the default value if it is set to NoEndDate. This works, but it is of course a hack. It would be great if we had something like a RecurrenceDialogInitializing event where we could intercept the object immediately after creation and adjust the values.

My behaviour:

/// <summary>
/// Workaround for setting default values in Recurrence editor of RadScheduleView.
/// </summary>
public class SetDefaultRecurrenceValuesOnLoad : Behavior<FrameworkElement>
{
    protected override void OnAttached()
    {
        this.AssociatedObject.Loaded += AssociatedObject_Loaded;
 
        base.OnAttached();
    }
 
    protected override void OnDetaching()
    {
        this.AssociatedObject.Loaded -= AssociatedObject_Loaded;
 
        base.OnDetaching();
    }
 
    void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
    {
        var rule = sender.GetDataContext<RecurrenceDialogViewModel>();
        if (rule != null)
        {
            if (rule.RecurrenceRangeType == RecurrenceRangeType.NoEndDate)
            {
                //NoEndDate is not allowed for our stuff, so we must change it here.
                rule.RecurrenceRangeType = RecurrenceRangeType.MaxOccurrences;
            }
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 25 Jan 2011, 08:52 AM
Hi Henrik,

We have such event - ShowDialog. It is called for all dialogs: AppointmentEdit, AppointmentDelete and Recurrence dialog. You can check the view model in the parameters to identify which type of dialog is showing and there you can initialize it.

I hope that this will help you.
Let us know if you need more information.

Kind regards,
Hristo
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
hwsoderlund
Top achievements
Rank 1
answered on 25 Jan 2011, 10:48 AM
Ok, I see. I actually tried that, but the event is not fired for the EditRecurrence dialog. It is fired for AppointmentEdit, AppointmentDelete and also for the "DeleteRecurrenceChoiceDialog" or whatever it is called, but not for EditRecurrence. So I will stick to my workaround until the bug is fixed, but now at least I know how it is supposed to be done. Thanks.

/Henrik
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 25 Jan 2011, 12:35 PM
Hi Henrik,

 As you correctly noticed this is a bug that will be fixed in the next internal build. Thank you for informing us for this problem!

All the best,
Miroslav Nedyalkov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
ScheduleView
Asked by
hwsoderlund
Top achievements
Rank 1
Answers by
Hristo
Telerik team
hwsoderlund
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Share this question
or