2014-05-11 10 views
7

मैं एक सार्वभौमिक ऐप के हिस्से के रूप में अपने विंडोज फोन 8 सिल्वरलाइट एप्लिकेशन को 8.1 फोन ऐप में बदलने की कोशिश कर रहा हूं। मुझे नहीं पता कि यह प्रासंगिक है क्योंकि यह पहली बार है जब मैंने दृश्य मॉडल को सही तरीके से कार्यान्वित करने का प्रयास किया है। मैं विंडोज और विंडोज फोन में विचारों के बीच डेटा साझा करना चाहता हूं। वैसे भी, यह वह त्रुटि है जो मुझे मिल रही है।एमवीवीएम लाइट "कैश में टाइप नहीं मिला"

Error 3 Type not found in cache: ScoreAlerts.ViewModel.FixturesViewModel. C:\Users\Dave\Documents\Visual Studio 2012\Projects\Score Alerts\ScoreAlerts\ScoreAlerts.WindowsPhone\Pages\Fixtures.xaml 9 5 ScoreAlerts.WindowsPhone 
Error 4 Type not found in cache: ScoreAlerts.ViewModel.HomePageViewModel. C:\Users\Dave\Documents\Visual Studio 2012\Projects\Score Alerts\ScoreAlerts\ScoreAlerts.Shared\Pages\HomePage.xaml 34 9 ScoreAlerts.WindowsPhone 

इस तरह मेरे विचार मॉडल लोकेटर लग रहा है

public class ViewModelLocator 
{ 
    /// <summary> 
    /// Initializes a new instance of the ViewModelLocator class. 
    /// </summary> 
    public ViewModelLocator() 
    { 
     if (!ViewModelBase.IsInDesignModeStatic) 
     { 
      ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); 

      if (ViewModelBase.IsInDesignModeStatic) 
      { 
       // Create design time view services and models 
       //SimpleIoc.Default.Register<IDataService, DesignDataService>(); 
      } 
      else 
      { 
       // Create run time view services and models 
       //SimpleIoc.Default.Register<IDataService, DataService>(); 
      } 

      SimpleIoc.Default.Register<HomePageViewModel>(); 
      SimpleIoc.Default.Register<FixturesViewModel>(); 
     } 
    } 

    [SuppressMessage("Microsoft.Performance", 
     "CA1822:MarkMembersAsStatic", 
     Justification = "This non-static member is needed for data binding purposes.")] 
    public HomePageViewModel Main 
    { 
     get 
     { 
      //return ServiceLocator.Current.GetInstance<HomePageViewModel>(); 
      return SimpleIoc.Default.GetInstance<HomePageViewModel>("default"); 
     } 
    } 

    [SuppressMessage("Microsoft.Performance", 
     "CA1822:MarkMembersAsStatic", 
     Justification = "This non-static member is needed for data binding purposes.")] 
    public FixturesViewModel Fixtures 
    { 
     get 
     { 
      //return ServiceLocator.Current.GetInstance<FixturesViewModel>(); 
      return SimpleIoc.Default.GetInstance<FixturesViewModel>("default"); 
     } 
    } 

    public static void Cleanup() 
    { 
     // TODO Clear the ViewModels 
    } 
} 

मेरा विचार XAML इस

DataContext="{Binding Fixtures, Source={StaticResource Locator}}" 

है तथा मेरे एप्लिकेशन को इस

<viewModel:ViewModelLocator x:Key="Locator" 
         d:IsDataSource="True"/> 

कोई भी विचार है कि मैं क्या मैं गलत कर रहा हूँ?

उत्तर

12

उत्तर एक काफी सरल गलती थी। इस बिट डिज़ाइन मोड में निष्पादित किया जा रहा नहीं कर रहा था

SimpleIoc.Default.Register<HomePageViewModel>(); 

SimpleIoc.Default.Register के लिए मेरे कोड(); एक कथन के अंदर था जिसे डिजाइन मोड में कभी निष्पादित नहीं किया गया था।

+0

त्रुटि दर्ज करने के बाद भी अभी भी जारी है। –

+0

यहां वही है और फिर भी मुझे एक और दर्जन अन्य व्यू मॉडल्स पंजीकृत हैं। समझ में नहीं आता कि यह क्यों इस त्रुटि को फेंक रहा है। अजीब चीज यह है कि यह एक खाली है और एक ही अमूर्त वर्ग से दूसरों के रूप में विरासत में मिलता है। उलझन में। कोई अन्य सुझाव? – Thierry

+0

जब आप कहते हैं कि डिज़ाइन मोड में थोड़ा सा कोड निष्पादित नहीं किया जा रहा था, तो आप यह नहीं कह रहे हैं कि आपने इसे कैसे ठीक किया है? क्या तुम समझा सकते हो? – Thierry

संबंधित मुद्दे