开发者

pass window as variable, wpf

开发者 https://www.devze.com 2023-01-11 01:25 出处:网络
Thank you for your help in advance. In the following code located in开发者_高级运维 Main(): Application.Run(new frmBackground(frmExit))

Thank you for your help in advance.

In the following code located in开发者_高级运维 Main(): Application.Run(new frmBackground(frmExit)) I am trying to launch window frmBackground that takes a window as a parameter in the constructor and after all content is loaded (background image), it then launches the passed window. This however does not compile and only compiles when I use Application.Run(new frmBackground(new frmExit())) which passess the correct window parameter, but on its own, creates an instance of frmExit and launches the window even when frmBackground code that launches the window is commented out.

Thank you again.


From what I understand, when you say Application.Run(new frmBackground(frmExit)), you're not passing an instance of frmExit, but the type (the class), and from what I understand, your method is expecting an instance... you might want to do something like:

frmExit exitForm = new frmExit();
Application.Run(new frmBackground(exitForm));

Or have some sort of "bag" class where you keep the reference of some resources you know you might need, like the reference for this form (frmExit), and change the constructor of frmBackground, then you replace the calls for the parameter variable with the values on your "bag" class.. something like that..

If this is not what you're trying to achieve, I'd suggest you give more details of your code here


pass the Type into the constuctor and then use reflection to create it in your frmBackground

This will show you how

Create an instance of a Type, provided as a parameter to a method

0

精彩评论

暂无评论...
验证码 换一张
取 消