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

Opening dialogs hangs the whole SL page

3 Answers 42 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 30 Sep 2011, 02:16 PM
I've hade a problem for quite a while now, but I thought it hade to do with the trial version.
Today we purchased and installed the developer version, but my problem stayed.

If I open an appointment from the ScheduleView, close it and open it again (or another one) then close it, my whole Silverlight page is disabled. Usually it's after two or three dialog open/close.

I have my own dialog factory that implements the IScheduleViewDialogHostFactory.
I also have my own edit appointment dialog which is a standard Silverlight ChildWindow that implements the IScheduleViewDialogHost interface.

I guess I'm doing something wrong when closing it perhaps?

public class TimeScheduleWindowFactory : IScheduleViewDialogHostFactory
    {
        public event EventHandler<WindowClosedEventArgs> EditShiftDialog_Closed;
        public event EventHandler<WindowClosedEventArgs> DeleteShiftDialog_Closed;
 
        private int actorCompanyId;
        private int userId;
        private TermUtility termUtil;
 
        public TimeScheduleWindowFactory(int actorCompanyId, TermUtility termUtil, int userId = 0)
        {
            this.userId = userId;
            this.actorCompanyId = actorCompanyId;
            this.termUtil = termUtil;
        }
 
        public IScheduleViewDialogHost CreateNew(ScheduleViewBase scheduleView, DialogType dialogType)
        {
            switch (dialogType)
            {
                case DialogType.AppointmentDialog:
                    // Create new AppointmentDialogHost
                    TimeScheduleShift shift = scheduleView.CurrentAppointment as TimeScheduleShift;
                    if (shift != null && shift.ActualStart == new DateTime())
                    {
                        shift.ActualStart = shift.Start;
                        shift.ActualEnd = shift.End;
                    }
                    EditShiftDialog editShiftDialog = new EditShiftDialog(termUtil, shift, actorCompanyId, userId);
                    editShiftDialog.ScheduleView = scheduleView;
                    editShiftDialog.Closed += new EventHandler<WindowClosedEventArgs>(AppointmentDialog_Closed);
                    editShiftDialog.Initialize();
                    return editShiftDialog;
                case DialogType.ConfirmationDialog:
                    // Create new ConfirmationDialogHost
                    DeleteShiftDialog deleteShiftDialog = new DeleteShiftDialog(termUtil, actorCompanyId);
                    deleteShiftDialog.ScheduleView = scheduleView;
                    deleteShiftDialog.Closed += new EventHandler<WindowClosedEventArgs>(ConfirmationDialog_Closed);
                    return deleteShiftDialog;
                case DialogType.RecurrenceChoiceDialog:
                    // Create new RecurrenceChoiceDialogHost
                    //throw new NotImplementedException();
                    break;
                case DialogType.RecurrenceDialog:
                    // Create new RecurrenceDialogHost
                    //throw new NotImplementedException();
                    break;
                default:
                    //throw new NotImplementedException();
                    break;
            }
 
            // TODO: Can't return null, it will crash!
            return null;
        }
 
        private void AppointmentDialog_Closed(object sender, WindowClosedEventArgs e)
        {
            if (EditShiftDialog_Closed != null)
                EditShiftDialog_Closed(sender, e);
        }
 
        private void ConfirmationDialog_Closed(object sender, WindowClosedEventArgs e)
        {
            if (DeleteShiftDialog_Closed != null)
                DeleteShiftDialog_Closed(sender, e);
        }


Regards,
Håkan

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivo
Telerik team
answered on 05 Oct 2011, 04:42 PM
Hi Håkan,

You will have to add boolean field into your ChildWindow class to mark if the Window is currently opened. And to call the IScheduleViewDialogHost.Close() method only if the window is opened. Here is sample code:
public partial class Window : ChildWindow, IScheduleViewDialogHost
{
    private bool opened;
 
    public Window()
    {
        InitializeComponent();
    }
 
    protected override void OnOpened()
    {
        base.OnOpened();
        this.opened = true;
    }
 
    protected override void OnClosed(System.EventArgs e)
    {
        base.OnClosed(e);
        if (this.Closed != null && this.opened)
        {
            this.opened = false;
            this.Closed(this, new WindowClosedEventArgs());
        }
    }
 
    public new event EventHandler<WindowClosedEventArgs> Closed;
 
    public ScheduleViewBase ScheduleView { get; set; }
 
      privatevoid IScheduleViewDialogHost.Close()
    {
        if (this.opened)
        {
            this.Close();
        }
    }
 
    public void Show(bool isModal)
    {
        this.Show();
    }
}

Best wishes,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Håkan
Top achievements
Rank 1
answered on 06 Oct 2011, 08:05 PM
Hi,

it almost worked now.
I tried to implement your sample, but the compiler gave me an error on
privatevoid IScheduleViewDialogHost.Close()

It says: The modifier 'private' is not valid for this item.
I tried public and protected override with no luck.

Changing it to just public void Close() without the interface name seemed to work at first. It worked for my edit child window. But when implementing the same in my delete confirmation dialog I got a stack overflow in that method when closing it. Regards, Håkan


0
Håkan
Top achievements
Rank 1
answered on 06 Oct 2011, 08:20 PM
I think I figured it out my self.

I had some old code raising the Closed event in my cancel button code. Removing it seemed to do the trick.

- Håkan
Tags
ScheduleView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Håkan
Top achievements
Rank 1
Share this question
or