c# - An object reference is required for the non-static field, method, or property 'TingTong.MainWindow.animategrid(string, string, string)' -


i have 2 classes shown below

animateutils class:

namespace tingtong.view {     public class animateutils     {          public static void animategrid(string motion, ref doubleanimation slide, ref grid grid, ref grid grid2, ref storyboard sbfade, ref storyboard sbslide)         {             if (motion == "away")             {                 slide.to = 310;                 slide.from = 0;             }             else             {                 slide.to = 0;                 slide.from = 310;             }              switch (grid.name)             {                 case "gd_lockscreen":                      slide.duration = new duration(timespan.frommilliseconds(400.0));                     storyboard.settarget(slide, grid);                     storyboard.settargetproperty(slide, new propertypath("rendertransform.(translatetransform.x)"));                     sbfade.children.add(slide);                     sbfade.begin();                     if (grid2.name == "gd_login")                     {                         slide.to = 0;                         slide.from = 310;                         slide.duration = new duration(timespan.frommilliseconds(400.0));                         storyboard.settarget(slide, grid2);                         storyboard.settargetproperty(slide, new propertypath("rendertransform.(translatetransform.x)"));                         sbslide.children.add(slide);                         sbslide.begin();                     }                     break;                 case "gd_login":                     slide.duration = new duration(timespan.frommilliseconds(400.0));                     storyboard.settarget(slide, grid);                     storyboard.settargetproperty(slide, new propertypath("rendertransform.(translatetransform.x)"));                     sbfade.children.add(slide);                     sbfade.begin();                     if (grid2.name == "gd_background")                     {                         slide.to = 310;                         slide.from = 0;                         slide.duration = new duration(timespan.frommilliseconds(800.0));                         storyboard.settarget(slide, grid2);                         storyboard.settargetproperty(slide, new propertypath("rendertransform.(translatetransform.x)"));                         sbslide.children.add(slide);                         sbslide.begin();                     }                     break;             }          }        } } } 

second class is:

namespace tingtong {       public partial class mainwindow : window     {  static void xmppcon_onlogin(object sender)         {              system.windows.messagebox.show("logged in server");               animategrid("loginscreen", "away", "backgroundimg");  <------error shown here          } 

private void animategrid(string grid, string motion, string withgrid) { switch (grid) { case "lockscreen":

                animateutils.animategrid(motion, ref slide, ref gd_lockscreen, ref gd_login, ref sbfade, ref sbslide);                 break;              case "loginscreen":                  animateutils.animategrid(motion, ref slide, ref gd_login, ref gd_background, ref sbfade, ref sbslide);                 break;         }       }        } 

}

however, getting following error:

error:an object reference required non-static field, method, or property 'tingtong.mainwindow.animategrid(string, string, string)'   d:\tingtong\tingtong\mainwindow.xaml.cs 400 13  tingtong 

try calling following, since, animategrid(...) method written inside animateutils class.

animateutils.animategrid("loginscreen", "away", "backgroundimg");   

also may need import 'tingtong.view' namespace on top, if not imported below:

using tingtong.view;  

edit

after taking close @ second class i.e. mainwindow in tingtong namespace, either have change animategrid() method signature to:

private static void animategrid(string grid, string motion, string withgrid) 

or

you have remove 'static' keyword in-front of event handler: xmppcon_onlogin(object sender)

you can not call non-static/instance methods static methods.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -