Closed event doesn't work

3 posts, 1 answers
  1. Eduardo
    Eduardo avatar
    15 posts
    Member since:
    Mar 2009

    Posted 02 Apr 2009 Link to this post

    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. Answer
    hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 03 Apr 2009 Link to this post

    I think you have to do the following, otherwise the windows will never actually be closed, just hidden.

    form.CloseMode = CloseMode.Close; 

  3. DevCraft banner
  4. Eduardo
    Eduardo avatar
    15 posts
    Member since:
    Mar 2009

    Posted 03 Apr 2009 Link to this post

    Thank you so much
Back to Top