生成期间发生XAMLParseException。

生成期间发生XAMLParseException。,xaml,windows-phone-8,Xaml,Windows Phone 8,我正在为一个项目构建一个WP8应用程序,它基本上从web导入一个XML文件,并在LongListSelector中显示内容 这是我的XAML代码 <phone:PhoneApplicationPage x:Class="TestApp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml

我正在为一个项目构建一个WP8应用程序,它基本上从web导入一个XML文件,并在LongListSelector中显示内容

这是我的XAML代码

<phone:PhoneApplicationPage
x:Class="TestApp.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"
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>
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <phone:LongListSelector x:Name="lb_country_list"
                                LayoutMode="List"
                                IsGroupingEnabled="true"
                                HideEmptyGroups ="true"
                                HorizontalAlignment="Left"
                                Height="655"
                                Margin="10,10,0,0"
                                VerticalAlignment="Top"
                                Width="436"
                                ItemTemplate="{StaticResource LLSItemTemplate}"/>

        <Button Content="Get Data" HorizontalAlignment="Left" Height="88" Margin="125,670,0,0" VerticalAlignment="Top" Width="221"/>

    </Grid>
</Grid>
<phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="LLSItemTemplate">
            <StackPanel>
            <TextBlock Margin="10"
                           Text="{Binding country_namef}"
                           TextWrapping="Wrap" 
                           Foreground="Black"/>
                <Line Grid.Row="1" X1="0" X2="480" Y1="0" Y2="0" Stroke="Gray" Margin="0"/>
            </StackPanel>
        </DataTemplate>



</phone:PhoneApplicationPage.Resources>

在MainPage.xaml.vb中的my InitializeComponent()中,附加信息准确地说明了问题所在:解析器无法找到资源
LLSItemTemplate
。你应该在
MainPage.xaml
App.xaml
中包含
LongListSelector
的itemtemplate,我想网上的教程已经过时了。他们指示创建模板并将模板放在那里。我没有在mainpage.xaml或app.xaml中包含itemtemplate,而是使用标记将其放在longlistselector标记中。无论如何,谢谢你的帮助。嗯,我不认为教程已经过时了。我在你的问题中漏掉了一些东西。我只是看到模板没有丢失,但它位于错误的位置。模板应在打开
PhoneApplicationPage
标记后立即出现。我试过你的代码,把模板移到了合适的位置,效果很好。是的,我不久前就意识到了这一点。
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll

Additional information: Cannot find a Resource with the Name/Key LLSItemTemplate [Line: 32 Position: 50]