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

Closed event doesn't work

2 Answers 62 Views
Window
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 02 Apr 2009, 07:34 PM

I create my windows this way:

        public static void CreateForm(String title, string classFullName, TypeShow typeShow, FrameworkElement positionReference, Dictionary<string, object> parameters, EventHandler<WindowClosedEventArgs> closedEvent)
        {
            UserControl userControl = (UserControl)Activator.CreateInstance(Type.GetType(classFullName));
            userControl.HorizontalAlignment = HorizontalAlignment.Left;
            userControl.VerticalAlignment = VerticalAlignment.Top;

            RadWindow form = new RadWindow();
            form.Content = userControl;
            form.Header = title;
            form.VerticalAlignment = VerticalAlignment.Center;
            form.HorizontalAlignment = HorizontalAlignment.Center;
            form.BorderThickness = new Thickness(1, 2, 1, 1);
            form.Background = new SolidColorBrush(Colors.White);

            LoadComboFilter(userControl);
            //ConfigKeyDownGrid(userControl);
                       
            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    if (userControl.GetType().GetProperty(parameter.Key) != null)
                        userControl.GetType().GetProperty(parameter.Key).SetValue(userControl, parameter.Value, null);
                }
            }

            if (closedEvent != null)
                form.Closed += closedEvent;

            form.Opened += new RoutedEventHandler(form_Opened);
            form.LostMouseCapture += new MouseEventHandler(form_LostMouseCapture);
            userControl.KeyDown += new KeyEventHandler(UserControl_KeyDown);

            switch (typeShow)
            {
                case TypeShow.Show:
                    form.Show();
                    break;
                case TypeShow.ShowModal:
                    form.ShowDialog();             
                    break;
                case TypeShow.ShowTab:
                    break;
                default:
                    form = null;
                    break;
            }
        }

        private void btnAtalhoGrupoHistorico_Click(object sender, RoutedEventArgs e)
        {
            UIFactory.CreateForm("Grupos de Histórico", "Publisoft.UI.PesGrupoHistorico", UIFactory.TypeShow.ShowModal, this, null, FormClose);
        }

        void FormClose(object sender, WindowClosedEventArgs e)
        {
            LoadCombpGrupoHistorico();
        }


...but when I click in "x" button of the window, the Closed event were not invoke!

2 Answers, 1 is accepted

Sort by
0
Accepted
hwsoderlund
Top achievements
Rank 1
answered on 03 Apr 2009, 08:51 AM
I think you have to do the following, otherwise the windows will never actually be closed, just hidden.

form.CloseMode = CloseMode.Close; 

0
Eduardo
Top achievements
Rank 1
answered on 03 Apr 2009, 11:25 AM
Thank you so much
Tags
Window
Asked by
Eduardo
Top achievements
Rank 1
Answers by
hwsoderlund
Top achievements
Rank 1
Eduardo
Top achievements
Rank 1
Share this question
or