.net - WPF - C#: This element is not currently associated with any context -


i have wpf usercontrol, use in winforms control within elementhostcontrol. start wpf window, while windows form still open. if close wpf window, , try add child element wpf usercontrol, crashes @ "initializecomponent()" (of child element) exception:

"a first chance exception of type 'system.configuration.configurationerrorsexception' occurred in system.configuration.dll. additional information: element not associated context"

i found out why happens, don't know how solve problem. if leave out code:

public static void ensureapplicationresources()     {         if (application.current == null)         {             // create application object             new application();             string assemblyname = system.io.path.getfilenamewithoutextension(                 assembly.getexecutingassembly().manifestmodule.name);              // merge in application resources             application.current.resources.mergeddictionaries.add(                 application.loadcomponent(new uri("/kolonistenclient;component/kolonistenresourcedictionary.xaml", urikind.relativeorabsolute))                 resourcedictionary);         }     } 

then fine. need though, because of fact resourcedictionary (and defined styles , templates) otherwise not available throughout wpf window , controls. this found out here

is there way combine best of both worlds? keeping resourcedictionary, while preventing application crashing?

i solved adding resourcedictionary in each window manually through xaml. way usercontrol in winforms stays unaffected.

still don't understand why crashed though, unfortunately.

<window.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="/kolonistenclient;component/kolonistenresourcedictionary.xaml"/>         </resourcedictionary.mergeddictionaries>     </resourcedictionary> </window.resources> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -