这个Xaml无效......我不明白为什么

时间:2013-07-24 12:59:21

标签: c# .net xaml binding windows-phone-8

我对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>

我从这里开始关注教程(与longlistselector不同):[http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286418(v=vs.105)。 ASPX] [1]

我怎么说一切正常,longlistselector给我看图像和联系人的名字。

显示结构:

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;
       }

    }
}

感谢每一位有帮助的人。

新细节: 错误在datatemplate AddrBookItemTemplate中签名,我注意到如果我离开图像源属性,错误就会消失。 所以似乎是绑定的东西。

2 个答案:

答案 0 :(得分:3)

  

Visual Studio for wp告诉我xaml无效但是当我执行应用程序时它工作正常。

请忽略设计师。这是喜怒无常的。

答案 1 :(得分:2)

这可能是一个糟糕的复制/粘贴,但您的第一个元素(<phone:PhoneApplicationPage>)并未关闭。