XAML 数据网格数据模板

标签 xaml windows-8 translate bing-api

我正在浏览Windows 8 Bing Translator Walkthrough

我能够遵循除 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>

最佳答案

...我一发布问题,就找到了答案。上述需要安排如下: 请注意,在上面提供的链接中的示例中,作者使用了 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>

希望这对其他人也有用。

保罗

关于XAML 数据网格数据模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14306447/

相关文章:

windows - InnoSetup - 如何要求用户键入许可证 key 或产品 key 并将该代码与编译常量匹配?

arrays - Logstash 拆分字段为多个字段或拆分数组为多个字段

wpf - 在 WPF ComboBox 上,是否可以为文本框和弹出窗口设置不同的前景色?

c# - Window.Show() 不显示窗口

c++ - 如何将 Qt Creator 配置为用户 MSVC2015?

properties - 如何获取 Windows 8 文件的修改日期?

c# - 如果 WPF 中没有子项,则隐藏 Expander ToggleButton

wpf - DataTrigger 上的 Storyboard未正确触发

php - 带占位符的 Symfony 翻译不起作用

Laravel 翻译值 required_if