I'm currently following the Pluralsight C# Fundamentals: Part 1
and on the Classes and Objects
section the video instructs me to create a new WPF Applicaiton in Visual Studio and fill in the code. This results in the following.
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Employee e1 = new Employee("Ash");
Employee e2 = new Employee("Lee");
Output.Text = e1.Name + "" + e2.Name;
}
}
}
Employee is basically a dummy class which has been defined with a single instance variable Name
in order to demonstrate how constructors work.
There is also a TextBlock
in my MainWindow.xaml
called Output
which I am trying to update on the last line of the code.
Initially I had the code contained in MainWindow_Loaded
in the constructor MainWindow
, the tutorial says this is bad practice and it should look like my first code snippet.
However this stops the application working. My question is what is the problem?
Is the tutorial outdated? Am I running the wrong version? Was it changed in Beta?
Thanks.
Make sure the Loaded event mapped to MainWindow_Loaded in the XAML for MainWindow.
Edit: Moving my comment below into the answer, as it seems to be more helpful:
open up MainWindow.xaml (not MainWindow.xaml.cs), click on the window (make sure you don't have one of the controls selected), open the properties box (i believe F4 will do that), click on the events tab in the properties box, find Loaded and make sure that is mapped to MainWindow_Loaded (if it is blank you should be able to select your already existing one)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With