title: Can a c#.net class be automatically initialized by databinding to one of the properties of the class?
body: <p>I am following a tutorial on <a href="http://msdn.microsoft.com/en-us/wp7trainingcourse_usingbingmapslab_topic3#_Toc271039355" rel="nofollow">http://msdn.microsoft.com/en-us/wp7trainingcourse_usingbingmapslab_topic3#_Toc271039355</a>. </p>
  
  <p>Source code can be found here: <a href="http://az12722.vo.msecnd.net/wp7trainingcourse1-4/labs/usingbingmapslab1-1-0/Source.zip" rel="nofollow">http://az12722.vo.msecnd.net/wp7trainingcourse1-4/labs/usingbingmapslab1-1-0/Source.zip</a>. Select the second project called "Ex2-HandlingPushpins"</p>
  
  <p>This tutorial shows how to place pins on a Bing map by long-pressing a location on the map. 
  In this tutorial there is a class PushpinCatalog, containing a collection of pushpins (Items). Items is bound to a ListBox control like this: </p>
  
  <pre><code>&lt;Popup x:Name="PushpinPopup" IsOpen="False" Canvas.Top="330" Canvas.Left="45" Opacity="0"&gt;
              &lt;ListBox x:Name="ListBoxPushpinCatalog"
                       Width="392" Height="56"
                       Background="{StaticResource ControlBackgroundBrush}"
                       ItemsSource="{Binding Items}"
                       SelectionChanged="ListBoxPushpinCatalog_SelectionChanged"&gt;
                  &lt;ListBox.ItemsPanel&gt;
                      &lt;ItemsPanelTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal" /&gt;
                      &lt;/ItemsPanelTemplate&gt;
                  &lt;/ListBox.ItemsPanel&gt;
                  &lt;ListBox.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Image Width="56" Height="56" Source="{Binding Icon}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListBox.ItemTemplate&gt;
                  &lt;ListBox.DataContext&gt;
                      &lt;models:PushpinCatalog /&gt;
                  &lt;/ListBox.DataContext&gt;
              &lt;/ListBox&gt;
          &lt;/Popup&gt;
  </code></pre>
  
  <p>And the Items collection is initialized in the constructor of the PushpinCatalog.
  My question is, when does the constructor of the PushpinCatalog get called? I tried right-clicking it and selecting "Find all references" in visual studio, but there are none.
  If I debug, the call stack shows this:</p>
  
  <pre><code>&gt;   UsingBingMaps.dll!UsingBingMaps.Models.PushpinCatalog.PushpinCatalog() Line 44 + 0x6 bytes  C#
      mscorlib.dll!System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo rtci, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object parameters, System.Globalization.CultureInfo culture, bool isBinderDefault, System.Reflection.Assembly caller, bool verifyAccess, ref System.Threading.StackCrawlMark stackMark) 
      mscorlib.dll!System.Reflection.RuntimeConstructorInfo.InternalInvoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture, ref System.Threading.StackCrawlMark stackMark) + 0x114 bytes    
      mscorlib.dll!System.Reflection.ConstructorInfo.Invoke(object[] parameters) + 0xa bytes  
      System.Windows.dll!MS.Internal.TypeProxy.GetCreateObjectDelegate.AnonymousMethod__2a() + 0xb bytes  
      System.Windows.dll!MS.Internal.TypeProxy.CreateInstance(uint customTypeId) + 0x12 bytes 
      System.Windows.dll!MS.Internal.FrameworkCallbacks.CreateKnownObject(System.IntPtr nativeRootPeer, uint customTypeId, string initializationString, out System.IntPtr nativePeer, uint isCreatedByParser) + 0x7a bytes    
      [External Code] 
      System.Windows.dll!MS.Internal.XcpImports.Application_LoadComponentNative(System.IntPtr pContext, System.IntPtr pComponent, uint cUriStringLength, string uriString, uint cXamlStrLength, byte* pXamlStr, uint cAssemblyStrLength, string assemblyStr)  
      System.Windows.dll!MS.Internal.XcpImports.Application_LoadComponent(MS.Internal.IManagedPeerBase componentAsDO, string resourceLocator, System.IO.UnmanagedMemoryStream stream, uint numBytesToRead, string assemblyString) + 0x39 bytes    
      System.Windows.dll!System.Windows.Application.LoadComponent(object component, System.Uri resourceLocator) + 0x136 bytes 
      UsingBingMaps.dll!UsingBingMaps.MainPage.InitializeComponent() Line 90 + 0x11 bytes C#
      UsingBingMaps.dll!UsingBingMaps.MainPage.MainPage() Line 51 + 0x6 bytes C#
      mscorlib.dll!System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo rtci, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object parameters, System.Globalization.CultureInfo culture, bool isBinderDefault, System.Reflection.Assembly caller, bool verifyAccess, ref System.Threading.StackCrawlMark stackMark) 
      mscorlib.dll!System.Reflection.RuntimeConstructorInfo.InternalInvoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture, ref System.Threading.StackCrawlMark stackMark) + 0x114 bytes    
      mscorlib.dll!System.Activator.InternalCreateInstance(System.Type type, bool nonPublic, ref System.Threading.StackCrawlMark stackMark) + 0xf0 bytes  
      mscorlib.dll!System.Activator.CreateInstance(System.Type type) + 0x2 bytes  
      Microsoft.Phone.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(System.AsyncCallback userCallback, System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult result) + 0xe6 bytes   
      Microsoft.Phone.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad.AnonymousMethod__0(object args) + 0x11 bytes  
      mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo rtmi, object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object parameters, System.Globalization.CultureInfo culture, bool isBinderDefault, System.Reflection.Assembly caller, bool verifyAccess, ref System.Threading.StackCrawlMark stackMark)   
      mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture, ref System.Threading.StackCrawlMark stackMark) + 0x168 bytes 
      mscorlib.dll!System.Reflection.MethodBase.Invoke(object obj, object[] parameters) + 0xa bytes   
      mscorlib.dll!System.Delegate.DynamicInvokeOne(object[] args) + 0x98 bytes   
      mscorlib.dll!System.MulticastDelegate.DynamicInvokeImpl(object[] args) + 0x8 bytes  
      mscorlib.dll!System.Delegate.DynamicInvoke(object[] args) + 0x2 bytes   
      System.Windows.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0xc bytes    
      System.Windows.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority) + 0x83 bytes  
      System.Windows.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context) + 0x8 bytes 
      System.Windows.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) + 0x19 bytes 
      System.Windows.dll!System.Windows.Hosting.DelegateWrapper.InternalInvoke(object[] args) + 0x2 bytes 
      System.Windows.RuntimeHost.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam[] pParams, ref System.Windows.Hosting.NativeMethods.ScriptParam pResult) + 0x5e bytes 
      [External Code] 
  </code></pre>
  
  <p>I suspect that through databinding of one of the properties of the class, the containing class is somehow automatically initialized, can anyone explain?</p>