silverlight - Can a c#.net class be automatically initialized by databinding to one of the properties of the class? -
i following tutorial on http://msdn.microsoft.com/en-us/wp7trainingcourse_usingbingmapslab_topic3#_toc271039355.
source code can found here: http://az12722.vo.msecnd.net/wp7trainingcourse1-4/labs/usingbingmapslab1-1-0/source.zip. select second project called "ex2-handlingpushpins"
this tutorial shows how place pins on bing map long-pressing location on map. in tutorial there class pushpincatalog, containing collection of pushpins (items). items bound listbox control this:
<popup x:name="pushpinpopup" isopen="false" canvas.top="330" canvas.left="45" opacity="0"> <listbox x:name="listboxpushpincatalog" width="392" height="56" background="{staticresource controlbackgroundbrush}" itemssource="{binding items}" selectionchanged="listboxpushpincatalog_selectionchanged"> <listbox.itemspanel> <itemspaneltemplate> <stackpanel orientation="horizontal" /> </itemspaneltemplate> </listbox.itemspanel> <listbox.itemtemplate> <datatemplate> <image width="56" height="56" source="{binding icon}" /> </datatemplate> </listbox.itemtemplate> <listbox.datacontext> <models:pushpincatalog /> </listbox.datacontext> </listbox> </popup>
and items collection initialized in constructor of pushpincatalog. question is, when constructor of pushpincatalog called? tried right-clicking , selecting "find references" in visual studio, there none. if debug, call stack shows this:
> 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]
i suspect through databinding of 1 of properties of class, containing class somehow automatically initialized, can explain?
the pushpincatalog class created during xaml processing.
<listbox.datacontext> <models:pushpincatalog /> - pushpincatalog instance creation </listbox.datacontext>
after datacontext property of listbox has reference pushpincatalog model instance.
Comments
Post a Comment