2013-01-13 58 views
2

我经历了Windows 8 Bing Translator WalkthroughXAML数据网格的DataTemplate

我能够跟随除了XAML部分的一切。我对XAML很陌生。以下是演练似乎推荐的内容,但是VS2012表示标记无效,并且显示的错误显示“属性”内容“设置了多次”。这是唯一的问题吗?在哪里设置不止一次?

<GridView ItemTemplate="{StaticResource TweetTemplate}" SelectionMode="None" ItemsSource="{Binding tweets}"></GridView> 
<DataTemplate x:Key="TweetTemplate"> 
     <Grid> 
      <Rectangle Fill="#FFDA713F" HorizontalAlignment="Left" Height="115" Margin="10,11,0,0" 
     VerticalAlignment="Top" Width="455" RadiusX="20" RadiusY="20"/> 
     <TextBlock Foreground="White" HorizontalAlignment="Left" Height="50" 
      Margin="176,12,0,0" TextWrapping="Wrap" x:Name="txtTweet" 
      Text="{Binding Title}" VerticalAlignment="Top" Width="277" FontSize="12"/> 
     <TextBlock Foreground="White" HorizontalAlignment="Left" Height="50" 
      Margin="176,72,0,0" TextWrapping="Wrap" x:Name="txtTrans" 
      Text="{Binding translatedText}" VerticalAlignment="Top" Width="277" 
      FontSize="12"/> 
     <Image Source="{Binding ImageUri}" HorizontalAlignment="Left" Height="89" 
      Margin="20,20,0,0" VerticalAlignment="Top" Width="116"/> 
     <TextBlock Foreground="White" HorizontalAlignment="Left" Height="17" 
      Margin="24,109,0,0" TextWrapping="Wrap" Text="{Binding Author}" 
      VerticalAlignment="Top" Width="150" FontSize="10"/> 

     </Grid> 
     </DataTemplate> 
+0

你把这个标记放在页面本身的哪里? DataTemplate通常位于Resources标签中;一旦我把它移到我的那边,那就没有问题了。我在做这件事之前遇到的问题不是“内容”错误,而是一个关于不正确放置模板的问题。 –

回答

2

...并且我不会提出问题,我找到答案。以上需要安排如下: 请注意,从上面提供的链接中的示例中,作者使用了RefreshAppBarButtonStyle。这已更改为AppBarButtonStyle。我不知道我完全理解xaml页面,但至少我有一个工作框架来诊断。

<Page.Resources> 
    <DataTemplate x:Key="TweetTemplate"> 
     <Grid> 
      <Rectangle Fill="#FFDA713F" HorizontalAlignment="Left" Height="115" Margin="10,11,0,0" VerticalAlignment="Top" Width="455" RadiusX="20" RadiusY="20"/> 
      <TextBlock Foreground="White" HorizontalAlignment="Left" Height="50" Margin="176,12,0,0" TextWrapping="Wrap" x:Name="txtTweet" Text="{Binding Title}" VerticalAlignment="Top" Width="277" FontSize="12"/> 
      <TextBlock Foreground="White" HorizontalAlignment="Left" Height="50" Margin="176,72,0,0" TextWrapping="Wrap" x:Name="txtTrans" Text="{Binding translatedText}" VerticalAlignment="Top" Width="277" FontSize="12"/> 
      <Image Source="{Binding ImageUri}" HorizontalAlignment="Left" Height="89" Margin="20,20,0,0" VerticalAlignment="Top" Width="116"/> 
      <TextBlock Foreground="White" HorizontalAlignment="Left" Height="17" Margin="24,109,0,0" TextWrapping="Wrap" Text="{Binding Author}" VerticalAlignment="Top" Width="150" FontSize="10"/> 

     </Grid> 
    </DataTemplate> 
</Page.Resources> 
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> 
    <GridView ItemTemplate="{StaticResource TweetTemplate}" SelectionMode="None" ItemsSource="{Binding tweets}"></GridView> 
</Grid> 
<Page.BottomAppBar> 
    <AppBar x:Name="bottomAppBar" Padding="10,0,10,0"> 
     <Grid> 
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> 
       <TextBlock x:Name="txtPrompt" Text="Search Term: " Height="24" FontSize="24"></TextBlock> 
       <TextBox x:Name="txtSearchTerm" Width="300" Height="24"></TextBox> 
       <Button Style="{StaticResource AppBarButtonStyle}" Click="Button_Click_1" /> 
      </StackPanel> 
     </Grid> 
    </AppBar> 
</Page.BottomAppBar> 

希望这对其他人也有用。

Paul