• 0

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


Question

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();
}
[/CODE]

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.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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?

Link to comment
Share on other sites

  • 0

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)

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

This topic is now closed to further replies.