4 Replies - 4499 Views - Last Post: 14 February 2012 - 01:33 PM Rate Topic: -----

#1 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

An object reference is required for the non-static field, method, or p

Posted 14 February 2012 - 10:11 AM

Hi everyone I am nearly new in vb.net and c# and I am converting from VB.Net to C# Net and I have this error.
An object reference is required for the non-static field, method, or property 'System.Windows.Application.Mainwindow.get'

this is in the last two lines: MainWindow = new iContract.UI.Master();
Mainwindow.Show();

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using System.Threading;
using System.Windows.Controls;
using Microsoft.VisualBasic;


namespace iContract 
{
    
    public partial class Application 
    {
        
     

       
        private void Application_Startup(object sender, System.Windows.StartupEventArgs e)

        {
           
        }

        public _dLoadSplash dLoadSplash = new _dLoadSplash(LoadSplash); 

        public delegate void _dLoadSplash(SplashWindow w);


        public static void LoadSplash(SplashWindow w)
       {
           Thread.Sleep(500);
           w.SetProgress(0.1);
           Thread.Sleep(500);
           w.SetProgress(0.3);
           Thread.Sleep(500);
           w.SetProgress(0.5);
           Thread.Sleep(500);
           w.SetProgress(0.7);
           Thread.Sleep(500);
           w.SetProgress(0.9);
           Thread.Sleep(500);
           w.SetProgress(1);
           Dispatcher.CurrentDispatcher.Invoke(new Action(CreateMainWindow), DispatcherPriority.Normal, null);
       }

        private static void CreateMainWindow()
        {
           MainWindow = new iContract.UI.Master();
            Mainwindow.Show();

        }
     
       
    }
}



thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: An object reference is required for the non-static field, method, or p

#2 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5101
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: An object reference is required for the non-static field, method, or p

Posted 14 February 2012 - 10:19 AM

You haven't declared Mainwindow. All variables must be declared before they are used.
Was This Post Helpful? 0
  • +
  • -

#3 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

Re: An object reference is required for the non-static field, method, or p

Posted 14 February 2012 - 12:01 PM

Hi Curtis, hoo sorry I think I haven't got you, I mean I convert this code from vb.net when it is working well, and I don't know exactly where I should declare this MainWindow
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5101
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: An object reference is required for the non-static field, method, or p

Posted 14 February 2012 - 12:38 PM

Ok, so basic C# learning includes learning how to declare a variable. For instance, if you wanted to create an integer variable, you'd declare it as such:

int myInteger;


So, do the same for your Mainwindow. Declare it as whatever type it actually is. In this case, you can do it right before the line that you use it.
Was This Post Helpful? 0
  • +
  • -

#5 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

Re: An object reference is required for the non-static field, method, or p

Posted 14 February 2012 - 01:33 PM

Hi Curtis :bigsmile: thanks so much. I did and its working Now. I really appreciate your quick answer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1