1

I add a window class in my WPF project as below:

    public partial class ParameterInput : Window
    {
       public ParameterInput()
       {
            InitializeComponent();            
       }

       public void show()
       {            
            bool ac= Activate();
        }
    }

And I do create a object of this class, and I hope it can be activated.

    void myTap(object sender, MouseButtonEventArgs e)
    {

        ParameterInput ParameterInputDialog= new ParameterInput();
        ParameterInputDialog.show();
        //bool ac = ParameterInputDialog.Activate();
    }

But I find this method do not work, the return value (ac) is false. why? Do anybody know how to solve this problem? I just want to open the dialog which I defined.

Ben
  • 15
  • 4

2 Answers2

0

this is because in Windows Forms and in WPF as well, to show a Window you should call its Show method not just the Activate one, try to call the Show Method instead, see an example here:

How to open second window from first window in wpf?

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • Yes. I add a Windows Forms class and call the show method. It do works, thank you. However, what I added in this project is a WPF window, and I find it have no show method, I need to rewrite this method, could you please tell me what I need to do? – Ben Feb 12 '15 at 18:44
  • You should be able to use show. Look at the second window class and make sure it subclasses Window. I do this currently with WPF and to show the window I use: RRWindow rr = new RRWindow(); rr.Show(); – Paul Gibson Feb 12 '15 at 19:53
  • Sorry, I do it as you say. The error information is : error CS1061: 'myproject.ParameterInput' does not contain a definition for 'show' and no extension method 'show' accepting a first argument of type 'myproject.ParameterInput' could be found. It seems like it really donot have the show method, and the ParameterInput Class does inherit from the Window class, as show in the picture above. – Ben Feb 12 '15 at 22:02
0

This question has be solved, please see: https://msdn.microsoft.com/en-us/library/system.windows.window.owner%28v=vs.110%29.aspx. So I change my code into:

    ParameterInput ParameterInputDialog= new ParameterInput();
    ParameterInputDialog.Owner = this;
    ParameterInputDialog.Show();

And it do works well. Thanks for all your help.

Ben
  • 15
  • 4