此Xaml无效..我没有';我不明白为什么

本文关键字:明白 为什么 Xaml 无效 | 更新日期: 2023-09-27 18:24:55

我对xaml有一个奇怪的问题。Visual studio for wp告诉我xaml无效,但当我执行应用程序时,它运行良好。

    <phone:PhoneApplicationPage
    x:Class="Friends_And_Money.ContList"
    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"
    xmlns:local="clr-namespace:Friends_And_Money"    
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">
    <!--LayoutRoot è la griglia radice in cui viene inserito tutto il contenuto della pagina-->
    <phone:PhoneApplicationPage.Resources>
        <local:ContactPictureConverter x:Key="ImageConverter" />
        <DataTemplate x:Key="AddrBookGroupHeaderTemplate">
            <Border Background="Transparent" Padding="5">
                <Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="62" 
         Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
                    <TextBlock Text="{Binding Key}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="48" Padding="6" 
            FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                </Border>
            </Border>
        </DataTemplate>
        <phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/>
        <phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/>
        <Style x:Key="AddrBookJumpListStyle" TargetType="phone:LongListSelector">
            <Setter Property="GridCellSize"  Value="113,113"/>
            <Setter Property="LayoutMode" Value="Grid" />
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Width="113" Height="113" Margin="6" >
                            <TextBlock Text="{Binding Key}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="48" Padding="6" 
                             Foreground="{Binding Converter={StaticResource ForegroundConverter}}" VerticalAlignment="Center"/>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="AddrBookItemTemplate">         
            <StackPanel VerticalAlignment="Top" Margin="0,5,0,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="5" ></ColumnDefinition>
                        <ColumnDefinition Width="auto" ></ColumnDefinition>
                        <ColumnDefinition Width="5" ></ColumnDefinition>
                        <ColumnDefinition Width="auto" ></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Image Source="{Binding Photo, Converter={StaticResource ImageConverter}}" Grid.Column="1" Width="62" Height="62" Stretch="Fill" />
                    <TextBlock Grid.Column="3" FontWeight="Light"  FontSize="40" Text="{Binding FirstName}" />
                </Grid>
            </StackPanel>
        </DataTemplate>

    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent">

        <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--TitlePanel contiene il nome dell'applicazione e il titolo della pagina-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"  Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="{Binding Path=LocalizedResources.ContactTitle, Source={StaticResource LocalizedStrings}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
        <!--ContentPanel - inserire ulteriore contenuto qui-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <phone:LongListSelector x:Name="LongList" 
                                    Background="Transparent"
                                    GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"
                                    ItemTemplate="{StaticResource AddrBookItemTemplate}"
                                    JumpListStyle="{StaticResource AddrBookJumpListStyle}"
                                    LayoutMode="List"
                                    IsGroupingEnabled="true"
                                    HideEmptyGroups ="true" />
        </Grid>
    </Grid>   
</phone:PhoneApplicationPage>

我从这里开始学习了教程(与长列表选择器不同):[http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286418(v=vs.105).aspx][1]

我怎么说一切都很好,长列表选择器显示我的图像和联系人的姓名。

显示结构:

namespace Friends_And_Money
{
    class ContactStruct 
    {
       public string FirstName
       {
          get;
          set;
       }
       public WriteableBitmap Photo
       {
          get;
          set;
       }
       public ContactStruct(string name, WriteableBitmap photo)
       {
          this.FirstName = name;
          this.Photo = photo;
       }
    }
}

感谢每一位提供帮助的人。

新详细信息:错误是在数据模板AddrBookItemTemplate中签名的,我注意到如果我保留图像源属性,错误就会消失。看来是有约束力的东西。

此Xaml无效..我没有';我不明白为什么

Visual studio for wp告诉我xaml无效,但当我执行应用程序时,它运行良好。

请忽略设计器。这相当情绪化。

这可能是一个错误的复制/粘贴,但您的第一个元素(<phone:PhoneApplicationPage>)没有关闭。