c# - Object reference is required for non-static TextBox -


c# n00b here. can't figure out why error on textbox.text saying:

enter image description here

on googling error, seems it's textbox being static..? can please explain means? how make non-static? have background in java, obj-c, python , swift if can draw similarities there.

code:

namespace wpfapplication2 {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();         }          private void button(object sender, routedeventargs e)         {             // create openfiledialog              microsoft.win32.openfiledialog dlg = new microsoft.win32.openfiledialog();                // set filter file extension , default file extension              dlg.defaultext = ".txt";             dlg.filter = "text files (*.txt)|*.text";               // display openfiledialog calling showdialog method              nullable<bool> result = dlg.showdialog();               // selected file name , display in textbox              if (result.hasvalue && result.value)             {                 // open document                  string filename = dlg.filename;                 textbox.text = filename;             }          }       } } 

if have textbox in xaml, this:

<textbox name="textbox1" width="100" height="50" /> 

you can reference code behind (in example mainwindow class) name this:

textbox1.text = "hello world"; 

the class textbox not static class. more info on static class see post:

c# different between static class , non-static (i talking class not field)


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -