【问题标题】:The name "ViewModelLocator" does not exist in the namespace (universal app)名称空间中不存在名称“ViewModelLocator”(通用应用程序)
【发布时间】:2015-03-10 09:20:35
【问题描述】:

我正在开发一个在 windows 8.1 和 windows phone 8.1 上运行的通用应用程序。

我遇到了 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>

【问题讨论】:

    标签: windows mvvm mvvm-light win-universal-app


    【解决方案1】:

    检查您的 ViewModelLocatorViewModel 类是否具有 public 访问权限,右键单击 Windows project - > 清理,最后构建

    【讨论】:

    • 感谢您的回答。我已经看到类似的答案以这种方式解决了这个问题。然而,就我而言,这不起作用。我还尝试为不同的架构进行编译,但我没有收到 x86 架构的错误。我最终做的是为 x86 编译以便具有“可混合性”,然后在设备中运行它。那样效果很好
    猜你喜欢
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 2018-12-26
    • 2016-11-06
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多