VS Developer Express for Windows Phone 新项目显示 XamlParseException [英] VS Developer Express for Windows Phone new project shows XamlParseException

查看:27
本文介绍了VS Developer Express for Windows Phone 新项目显示 XamlParseException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近为 Windows Phone 安装了 Windows 8 和 Visual Studio Express 2012.但是,如果我启动一个新的 Windows Phone App 项目(7.1,虽然 8 也有同样的问题)并打开 MainPage.xaml 文件,在设计器窗口中会出现如下错误:

I recently installed windows 8 along with Visual Studio Express 2012 for Windows Phone. However, if I start a new Windows Phone App project (7.1, although 8 has the same issue) and open the MainPage.xaml file, an error appears in the designer window as follows:

XamlParseException: Cannot find a Resource with the Name/Key PhoneBackgroundBrush [Line: 47 Position: 111]

MainPage.xaml 文件如下:

The MainPage.xaml file is as follows:

<phone:PhoneApplicationPage 
    x:Class="PhoneApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
    </Grid>

</phone:PhoneApplicationPage>

App.xaml 文件包含以下内容:

The App.xaml file contains this:

<Application 
    x:Class="PhoneApp1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
    </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>

解决方案如下:

似乎没有任何其他与样式相关的文件.任何人都可以对此有所了解吗?它让我发疯.

There doesn't appear to be any other style related files anywhere. Can anyone shed any light on this? its driving me insane.

推荐答案

根据您自己的答案,而不是复制原始 ThemesResources.xaml 我会创建一个新的并将其与原始的合并.

Based on your own answer instead of copying the original ThemesResources.xaml I'd create a new one and merge it with the original.

创建一个新的资源字典(例如 FixedDictionaryResources.xaml).在 Visual Studio 中,您需要创建一个 Windows Phone 页面或使用任何其他创建 XAML 文件的模板.在 Blend 中,您可以直接创建资源字典.在VS中,您需要删除所有内容并放入以下代码.在 Blend 中只需添加

Create a new Resource Dictionary (e.g. FixedDictionaryResources.xaml). In Visual Studio you need to create a Windows Phone Page or use any other template that creates a XAML file. In Blend you can create a resource dictionary directly. In VS you need to remove then all the content and put in the following code. In Blend just add the

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- Resource dictionary entries should be defined here. -->
    <SolidColorBrush x:Key="PhoneBackgroundBrush" Color="{StaticResource PhoneBackgroundColor}"/>
</ResourceDictionary>

打开 App.xaml 并添加以下代码以将新字典与默认资源字典合并.

Open App.xaml and add the following code to merge the new dictionary with the default resources dictionary.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/FixingResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

重新打开仍然显示 PhoneBackgroundBrush 丢失问题的页面,现在一切正常.

Reopen the pages that are still showing the PhoneBackgroundBrush missing issue and everything should work now.

这篇关于VS Developer Express for Windows Phone 新项目显示 XamlParseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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