C# n00b here. I can't figure out why I get the error on TextBox.text
saying:
On googling the error, it seems like it's to do with my TextBox being static..? I can you please explain what this all means? How do I make it non-static? I have a good background in Java, Obj-C, Python and Swift if you can draw any similarities from there.
Code:
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for 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 for file extension and default file extension
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.text";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result.HasValue && result.Value)
{
// Open document
string filename = dlg.FileName;
TextBox.Text = filename;
}
}
}
}