XAML 分析异常编译 Windows Phone 8 项目

本文关键字:Phone 项目 Windows 编译 异常 XAML | 更新日期: 2023-09-27 18:34:09

我正在尝试在Visual Studio IDE 2013上编译Windows Phone 8项目,但在解析MainPage.xaml时遇到错误。

在下面的代码中,我得到错误Windows.UI.Xaml.Markup.XamlParseException.我错了什么?该问题起源于开头AppBar标签的行。

<Page
    x:Class="MainStream.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MainStream"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid>
        <Image Grid.RowSpan="2" Stretch="None" Source="/img/sfondo.png" VerticalAlignment="Top" HorizontalAlignment="Center"/>
        <FlipView x:Name="flipView1" Width="480" Height="270" Margin="0,10,0,0" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1">
            <Image Width="480" Height="270" Stretch="UniformToFill"/>
            <TextBlock FontFamily="Segoe UI" FontSize="26.667" Foreground="#CCFFFFFF" Padding="15,20"/>
        </FlipView>
        <AppBar VerticalAlignment="Bottom" HorizontalAlignment="Center">
            <StackPanel Orientation="Horizontal">
                <AppBarButton Click="Play_Click" Label="Play" Icon="Play"/>
                <AppBarButton Click="Pause_Click" Label="Pause" Icon="Pause"/>
            </StackPanel>
        </AppBar>
    </Grid>
</Page>

错误是:

无法创建类型为 '%0' 的实例 [行:18 位置:17] 找不到与此错误代码关联的文本。

任何人都可以建议我一个解决方案吗?

XAML 分析异常编译 Windows Phone 8 项目

我不

认为应用栏应该是网格元素的子元素,我不确定您是否为应用栏使用了正确的格式。正确的方法类似于以下内容:

<Page
    x:Class="MainStream.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MainStream"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid>
        <Image Grid.RowSpan="2" Stretch="None" Source="/img/sfondo.png" VerticalAlignment="Top" HorizontalAlignment="Center"/>
        <FlipView x:Name="flipView1" Width="480" Height="270" Margin="0,10,0,0" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1">
            <Image Width="480" Height="270" Stretch="UniformToFill"/>
            <TextBlock FontFamily="Segoe UI" FontSize="26.667" Foreground="#CCFFFFFF" Padding="15,20"/>
        </FlipView>
   </Grid>
    <Page.BottomAppBar>
        <CommandBar Opacity="1">
            <AppBarButton x:Name="AddAppBarButton" Label="add" Icon="Add"  />
            <CommandBar.SecondaryCommands>
                <AppBarButton x:Uid="SecondaryButton1" x:Name="SecondaryButton1" Label="secondary command 1" />
                <AppBarButton x:Uid="SecondaryButton2" x:Name="SecondaryButton2" Label="secondary command 2" />
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
</Page>

尝试在这段代码中做任何你想做的事情,它可以是Page.TopAppBar的,也可以是Page.BottomAppBar的。

<Page.TopAppBar>
<AppBar>
    <!-- AppBar content -->
</AppBar>
</Page.TopAppBar>

尝试参考此内容以获取更多信息:

添加应用栏

  <Page x:Class="MainStream.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MainStream"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Page.BottomAppBar>
          <AppBar VerticalAlignment="Bottom" HorizontalAlignment="Center">
           <Grid>
            <StackPanel Orientation="Horizontal">
                <AppBarButton Click="Play_Click" Label="Play" Icon="Play"/>
                <AppBarButton Click="Pause_Click" Label="Pause" Icon="Pause"/>
            </StackPanel>
            <Image Grid.RowSpan="2" Stretch="None" Source="/img/sfondo.png" VerticalAlignment="Top" HorizontalAlignment="Center"/>
            <FlipView x:Name="flipView1" Width="480" Height="270" Margin="0,10,0,0" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1">
                <Image Width="480" Height="270" Stretch="UniformToFill"/>
                <TextBlock FontFamily="Segoe UI" FontSize="26.667" Foreground="#CCFFFFFF" Padding="15,20"/>
            </FlipView>    
        </Grid>
         </AppBar>
       </Page.BottomAppBar> 
</Page>

修改帮助程序类。

App myApp = new App();

以下是从 App.xaml 页面访问属性的正确方法。

App thisApp = (App)System.Windows.Application.Current;