Jump to content



Photo

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

wpf c#

  • Please log in to reply
6 replies to this topic

#1 James Rose

James Rose

    Software Developer

  • Tech Issues Solved: 1
  • Joined: 20-January 04
  • Location: New York City

Posted 18 August 2012 - 20:24

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.


#2 stumper66

stumper66

    Neowinian

  • Joined: 08-January 09
  • Location: Dallas, TX, USA

Posted 18 August 2012 - 21:37

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?

#3 OP James Rose

James Rose

    Software Developer

  • Tech Issues Solved: 1
  • Joined: 20-January 04
  • Location: New York City

Posted 18 August 2012 - 21:58

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)

#4 OP James Rose

James Rose

    Software Developer

  • Tech Issues Solved: 1
  • Joined: 20-January 04
  • Location: New York City

Posted 18 August 2012 - 22:33

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

Anyway....

#5 Descartes

Descartes

    Neowinian

  • Joined: 29-November 08
  • Location: Poland

Posted 19 August 2012 - 19:12

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.

#6 OP James Rose

James Rose

    Software Developer

  • Tech Issues Solved: 1
  • Joined: 20-January 04
  • Location: New York City

Posted 20 August 2012 - 13:46

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.

#7 Aethec

Aethec

    Neowinian Senior

  • Joined: 02-May 10

Posted 20 August 2012 - 23:11

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



Click here to login or here to register to remove this ad, it's free!