मेरे यूडब्लूपी ऐप के विकास के दौरान मैंने देखा है और अजीबता को अंतःस्थापित करना है जिसमें मुझे समझने में कठिनाई है।यूडब्ल्यूपी ऐप में मर्ज किए गए रिसोर्स डिक्शनरी इनलाइलाइजेशन
मैं उपयोगकर्ता MvvmLight और मैं एक अलग ResourceDictionary Core.xaml जो App.xaml में MergedDictionaries
से संदर्भित किया जाएगा में ViewModelLocator संसाधन उदाहरण जोड़ने का निर्णय लिया।
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Core.xaml" />
<ResourceDictionary Source="Resources/Converters.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
की सामग्री Core.xaml: बाद की सामग्री App.xaml है
<ResourceDictionary ...>
<viewModel:ViewModelLocator x:Key="Locator" />
</ResourceDictionary>
अब मैं Core.xamlमें संसाधनों की अपेक्षा की InitializeComponent
दौरान प्रारंभ कर रहे हैं विधि कॉल App.xaml.cs, लेकिन जब मैंने ServiceLocator
कक्षा का उपयोग करने का प्रयास किया (जो व्यूमोड के निर्माता में सेट है
An exception of type 'System.InvalidOperationException' occurred in
Microsoft.Practices.ServiceLocation.dll but was not handled in user code
Additional information: ServiceLocationProvider must be set.
वास्तव में, अगर मैं ViewModelLocator के निर्माता में एक ब्रेकपाइंट शब्दों में कहें, यह पहले खिड़की सक्रिय है नहीं बुलाया जाता है: MvvmLight में lLocator) - इस तरह - - ServiceLocator.Current.GetInstance<INavigationService>().Navigate<MainViewModel>();
मैं एक अपवाद कह मिलता है। अधिक दिलचस्प बात यह है कि - यदि मैं मैन्युअल रूप से लोकेटर संसाधन कुंजी का संदर्भ देता हूं (उदाहरण के लिए Debug.WriteLine(Resources["Locator"]);
ServiceLocator
के कॉल से ऊपर), सब कुछ ठीक काम करता है। वैसे ही अगर मैं ViewModelLocator
संसाधन सीधे App.xaml पर ले जाता हूं - तो इसे IntializeComponent
के दौरान तत्काल चालू किया जाता है।
क्या यूडब्ल्यूपी ऐप्स में विलय संसाधन शब्दकोशों का आलसी तात्कालिकता है? या यह इस तरह से क्यों व्यवहार करता है?
मैंने देखा कि यह अजीब व्यवहार तब होता है जब आपके संसाधन डिक्शनरी में कई सामान्य (शैली नहीं) वस्तुएं होती हैं। केवल एक ViewModelLocator पूरी तरह से काम करता है और ctor कहा जा रहा है। मेरे निष्कर्ष http://stackoverflow.com/questions/34466035/uwp-resourcedictionary-is-not-being-loaded-when-i-add-a-second-object-to-it –