2015-01-12 46 views
1

我正在開發一個在Windows 8.1和Windows Phone 8.1上運行的通用應用程序。名稱空間(通用應用程序)中不存在名稱「ViewModelLocator」

我遇到了App.xaml文件標題中提到的錯誤。 App.xaml文件位於MyApp.Shared項目中,ViewModel文件夾也是如此。 但是,錯誤只發生在Windows 8.1應用程序中。 Windows Phone應用程序運行良好,這是非常奇怪的,因爲它們運行完全相同的代碼。

在Windows 8.1應用程序中,我無法使用ViewModelLocator及其屬性,因此無法爲任何頁面設置DataContext。 (綁定無法解析,並且隨時嘗試打開帶有通過ViewModelLocator定義的DataContext的頁面時應用程序崩潰)。

貝婁是我的App.xaml文件

<Application 
x:Class="MyApp.App" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:MyApp"> 
<Application.Resources> 
    <ResourceDictionary > 
     <!-- This is where the error is --> 
     <vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:MyApp.ViewModel" /> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/Resources/Colors.xaml"/> 
      <ResourceDictionary Source="/Resources/Styles.xaml"/> 
     </ResourceDictionary.MergedDictionaries>   
    </ResourceDictionary>  
</Application.Resources> 

回答

1

檢查您ViewModelLocator視圖模型類具有公共訪問,之後在右鍵單擊Windows 項目 - >Clean,最後Build

+1

感謝您的回答。我已經看到類似的答案,這種方式解決這個問題。但在我的情況下,這是行不通的。我也嘗試編譯不同的體系結構,我沒有得到x86體系結構的錯誤。 我最終做的是編譯x86以便具有「可混合性」,然後在設備中運行它。它可以很好地工作 – Corcus

相關問題