1

I have the following code

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();

        }
    }
}

where do I find the code for this InitializeComponent(); I have no idea what its doing. thanks

Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221

3 Answers3

6

InitializeComponent is implemented on the other side of your partial class. It is auto-generated code, and determines the components and controls used on your page, it's positions, etc.

If you want to look at the implementation you can put your cursor on it's name and hit F12 (only works on VisualStudio :)

Also, you can check the official documentation here or this nice answer

Community
  • 1
  • 1
mcabral
  • 3,524
  • 1
  • 25
  • 42
4

It's provided by the designer-generated code created from your XAML. You can look for this in the obj directory - it'll be called MainPage.g.cs IIRC. Normally you don't need to look at this; just keep the InitializeComponent call where it is, and know that the designer will do the relevant magic for you :) (Obviously it's good to know what the magic is really though.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
4

As you can see from this line of code :

 public partial class MainPage : UserControl    {

this is a Partial class, so not all code is showed in this file.

If you use Visual Studio you can use F12 (or right click and Go To Definition) and the IDE go directly to the method.

2GDev
  • 2,478
  • 1
  • 20
  • 32