Sign in to follow this  
Followers 0

[WPF / C#] New window's TOP property


7 posts in this topic

Posted

Hello gang,

I need to be able to create a new window for each monitor and I have the following code:


			    foreach (var screen in System.Windows.Forms.Screen.AllScreens)

			    {

				    MainWindow MoodWindow = new MainWindow();

				    MoodWindow.Width = screen.WorkingArea.Width;

				    MoodWindow.Height = screen.WorkingArea.Height;

				    MoodWindow.Left = screen.WorkingArea.X;

				    MoodWindow.Top = 0;

				    MoodWindow.Show();

			    }

Everything works fine, except the .TOP property. It will not compile and says: "Cannot implicitly convert type 'int' to 'System.Windows.Controls.Grid'" WTH?

I'm sure this will be very stupid of me... so feel free to laugh.

Share this post


Link to post
Share on other sites

Posted

Using .Net 4.5, and assuming MainWindow is a custom System.Windows.Forms.Form, the above code shows no error for me.

Perhaps you have a public property named Top in there?

Share this post


Link to post
Share on other sites

Posted

Using .Net 4.5, and assuming MainWindow is a custom System.Windows.Forms.Form, the above code shows no error for me.

Perhaps you have a public property named Top in there?

I am using Visual Studio 2010 and the 4.0 frameworks. This is a WPF app and I have added "System.Windows.Forms" so that I can have access to the Screens object (multi monitor app) and yes, using that kind of defeats the purpose of using WPF. I know.

The MainWindow is just the standard window you get when you start a new WPF app. (trying out some new things)

Share this post


Link to post
Share on other sites

Posted

Well... that's odd. I have been adding some of the other code necessary and the issue has done away.... ??!

Anyway....

Share this post


Link to post
Share on other sites

Posted

This is a WPF app and I have added "System.Windows.Forms" so that I can have access to the Screens object (multi monitor app) and yes, using that kind of defeats the purpose of using WPF. I know.

Not really, I think this is a pretty common trick actually.

Anyway, I have an idea. Go to the code snippet you posted, right click the MoodWindow.Top part, choose "Go to definition" and see where it takes you. I suspect it might be an ambiguity or scoping problem.

EDIT: Sorry, I haven't realized that you've already fixed it.

Share this post


Link to post
Share on other sites

Posted

Not really, I think this is a pretty common trick actually.

Anyway, I have an idea. Go to the code snippet you posted, right click the MoodWindow.Top part, choose "Go to definition" and see where it takes you. I suspect it might be an ambiguity or scoping problem.

EDIT: Sorry, I haven't realized that you've already fixed it.

Thanks anyway.... and it fixed itself... which is odd. (to say the least) I simply went on to add a new function (no code that affected that function) and an hour later the bug was not there. Very strange.

Share this post


Link to post
Share on other sites

Posted

Sometimes rebuilding the solution or manually deleting the obj\ and bin\ folders works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.