在App.xaml中的错误尝试使用MVVM光在Windows Phone 8的项目 [英] Errors in App.xaml trying to use MVVM Light in Windows Phone 8 project

查看:239
本文介绍了在App.xaml中的错误尝试使用MVVM光在Windows Phone 8的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我经过的NuGet添加MVVM光包我得到的错误引用在安装过程中添加的App.xaml文件的行。这些错误只出现在Windows Phone 8的项目。在Windows Phone 7的项目完全相同的线路不会引起任何错误。该MVVM光加行是:

 <的ResourceDictionary>
    < VM:ViewModelLocator X:关键=定位器D:IsDataSource =真/>
     < ResourceDictionary.MergedDictionaries>< /ResourceDictionary.MergedDictionaries>
< / ResourceDictionary中>
 

这些线路只是结束的&LT前定位; /Application.Resources> 标记。 报告中的错误列表窗格中的错误是:

  • 在每个字典必须有一个相关联的密钥
  • 命名为ViewModelLocator没有命名空间存在CLR命名空间:sdkVoiceAlarmClockWP8CS.ViewModel

这似乎让因为在&LT感; ResourceDictionary中> 标签没有一个关键属性。不过,如果我尝试移动线的该块外的 块,我得到一组全新的误区。

至于ViewModelLocator问题而言,我双重检查和以下命名空间添加到<应用> 标签作为一种属性,它不标记有任何错误:

 的xmlns:VM =CLR的命名空间:sdkVoiceAlarmClockWP8CS.ViewModelMC:可忽略=D
 

为什么这完全一样的套系中的一款Windows Phone 7项目做工精细,我怎么能修复我的Windows Phone上的空间问题,我有8项目?

以防万一,这是由于一个更复杂的问题,这里是整个的App.xaml 文件:

 < XML版本=1.0编码=UTF-8&GT?;
<! - 
    版权所有(c)2012 Microsoft公司。版权所有。
    使用此示例源$ C ​​$ c是受Microsoft许可协议的条款
    根据该协议,您许可的这个示例源$ C ​​$ c和提供AS-IS。
    如果你不接受许可协议中的条款,则无权
    使用此示例源$ C ​​$ C。对于许可证的条款,请参阅
    您和微软之间的许可协议。

    要查看所有code样品为Windows Phone,请访问http://go.microsoft.com/fwlink/?LinkID=219604
 - >
<应用X:类=AlarmClockWithVoice.App
             XMLNS:手机=CLR的命名空间:Microsoft.P​​hone.Controls;装配= Microsoft.P​​hone
             的xmlns:SHELL =CLR的命名空间:Microsoft.P​​hone.Shell;装配= Microsoft.P​​hone
             的xmlns:工具箱=CLR的命名空间:Microsoft.P​​hone.Controls;装配= Microsoft.P​​hone.Controls.Toolkit
             xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
             的xmlns:P1 =htt​​p://schemas.microsoft.com/winfx/2006/xaml
             的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
             的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
             的xmlns:D =htt​​p://schemas.microsoft.com/ex$p$pssion/blend/2008
             的xmlns:MC =htt​​p://schemas.openxmlformats.org/markup-compatibility/2006
             的xmlns:VM =CLR的命名空间:sdkVoiceAlarmClockWP8CS.ViewModelMC:可忽略=D
             >

    <! - 应用程序资源 - >
    < Application.Resources>
        <风格X:关键=TransitionPageStyle的TargetType =电话:PhoneApplicationPage>
            < setter属性=工具包:TransitionService.NavigationInTransition>
                < Setter.Value>
                    <工具箱:NavigationInTransition>
                        <工具箱:NavigationInTransition.Backward>
                            <工具箱:TurnstileTransition模式=BackwardIn/>
                        < /工具包:NavigationInTransition.Backward>
                        <工具箱:NavigationInTransition.Forward>
                            <工具箱:TurnstileTransition模式=ForwardIn/>
                        < /工具包:NavigationInTransition.Forward>
                    < /工具包:NavigationInTransition>
                < /Setter.Value>
            < /二传手>
            < setter属性=工具包:TransitionService.NavigationOutTransition>
                < Setter.Value>
                    <工具箱:NavigationOutTransition>
                        <工具箱:NavigationOutTransition.Backward>
                            <工具箱:TurnstileTransition模式=BackwardOut/>
                        < /工具包:NavigationOutTransition.Backward>
                        <工具箱:NavigationOutTransition.Forward>
                            <工具箱:TurnstileTransition模式=ForwardOut/>
                        < /工具包:NavigationOutTransition.Forward>
                    < /工具包:NavigationOutTransition>
                < /Setter.Value>
            < /二传手>
        < /样式和GT;
        <的ResourceDictionary>
            < VM:ViewModelLocator X:关键=定位器D:IsDataSource =真/>
            < ResourceDictionary.MergedDictionaries>< /ResourceDictionary.MergedDictionaries>
        < / ResourceDictionary中>
    < /Application.Resources>

    < Application.ApplicationLifetimeObjects>
        <! - 所需的对象处理生命周期事件应用程序 - >
        <外壳:PhoneApplicationService发起=Application_Launching闭幕=Application_Closing激活=Application_Activated已停用=Application_Deactivated/>
    < /Application.ApplicationLifetimeObjects>

< /用途>
 

解决方案

我以前有这个问题。为了使其在WP8工作替换这样的:

<的ResourceDictionary>     < VM:ViewModelLocator X:关键=定位器D:IsDataSource =真/>     < ResourceDictionary.MergedDictionaries>< /ResourceDictionary.MergedDictionaries> < / ResourceDictionary中>

通过如此:

< VM:ViewModelLocator X:关键=定位器D:IsDataSource =真/>

但我没有打扰,为什么它适用于WP7,但不是WP8

When I add the MVVM Light package via NuGet I get errors referencing the lines in the App.xaml file added during the install. These errors only appear in Windows Phone 8 projects. The exact same lines in a Windows Phone 7 project do not raise any errors. The MVVM Light added lines are:

<ResourceDictionary>
    <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
     <ResourceDictionary.MergedDictionaries></ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

These lines are positioned just before the ending </Application.Resources> tag. The errors reported in the Error List pane are:

  • Each dictionary must have an associated key
  • The name "ViewModelLocator" does not exist in the namespace "clr-namespace:sdkVoiceAlarmClockWP8CS.ViewModel"

This seems to make sense since the <ResourceDictionary> tag does not have a key attribute. However, if I try to move this block of lines outside the block, I get a whole new set of errors.

As far as the ViewModelLocator problem is concerned, I double-checked and the following namespace is added to the <Application> tag as an attribute and it is not flagged with any errors:

xmlns:vm="clr-namespace:sdkVoiceAlarmClockWP8CS.ViewModel" mc:Ignorable="d"

Why does this exact same set of lines work fine in a Windows Phone 7 project and how can I fix the namespace problems I am having in my Windows Phone 8 project?

Just in case this is due to a more complex problem here is the entire App.xaml file:

<?xml version="1.0" encoding="utf-8"?>
<!-- 
    Copyright (c) 2012 Microsoft Corporation.  All rights reserved.
    Use of this sample source code is subject to the terms of the Microsoft license 
    agreement under which you licensed this sample source code and is provided AS-IS.
    If you did not accept the terms of the license agreement, you are not authorized 
    to use this sample source code.  For the terms of the license, please see the 
    license agreement between you and Microsoft.

    To see all Code Samples for Windows Phone, visit http://go.microsoft.com/fwlink/?LinkID=219604
-->
<Application x:Class="AlarmClockWithVoice.App" 
             xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
             xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
             xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
             xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives" 
             xmlns:p1="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:vm="clr-namespace:sdkVoiceAlarmClockWP8CS.ViewModel" mc:Ignorable="d"
             >

    <!--Application Resources-->
    <Application.Resources>
        <Style x:Key="TransitionPageStyle" TargetType="phone:PhoneApplicationPage">
            <Setter Property="toolkit:TransitionService.NavigationInTransition">
                <Setter.Value>
                    <toolkit:NavigationInTransition>
                        <toolkit:NavigationInTransition.Backward>
                            <toolkit:TurnstileTransition Mode="BackwardIn" />
                        </toolkit:NavigationInTransition.Backward>
                        <toolkit:NavigationInTransition.Forward>
                            <toolkit:TurnstileTransition Mode="ForwardIn" />
                        </toolkit:NavigationInTransition.Forward>
                    </toolkit:NavigationInTransition>
                </Setter.Value>
            </Setter>
            <Setter Property="toolkit:TransitionService.NavigationOutTransition">
                <Setter.Value>
                    <toolkit:NavigationOutTransition>
                        <toolkit:NavigationOutTransition.Backward>
                            <toolkit:TurnstileTransition Mode="BackwardOut" />
                        </toolkit:NavigationOutTransition.Backward>
                        <toolkit:NavigationOutTransition.Forward>
                            <toolkit:TurnstileTransition Mode="ForwardOut" />
                        </toolkit:NavigationOutTransition.Forward>
                    </toolkit:NavigationOutTransition>
                </Setter.Value>
            </Setter>
        </Style>
        <ResourceDictionary>
            <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
            <ResourceDictionary.MergedDictionaries></ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService Launching="Application_Launching" Closing="Application_Closing" Activated="Application_Activated" Deactivated="Application_Deactivated" />
    </Application.ApplicationLifetimeObjects>

</Application>

解决方案

I had this problem before. To make it work in WP8 replace this:

<ResourceDictionary>
    <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
    <ResourceDictionary.MergedDictionaries></ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

With just this:

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

But I haven't bothered as to why it works on WP7 but not WP8

这篇关于在App.xaml中的错误尝试使用MVVM光在Windows Phone 8的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆