【发布时间】: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