Changing default values on recurrence object

4 posts, 1 answers
  1. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 24 Jan 2011 Link to this post

    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;
                }
            }
        }
    }
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 25 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 25 Jan 2011 Link to this post

    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
  5. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 25 Jan 2011 Link to this post

    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>>
Back to Top