【问题标题】:XAML datagrid datatemplateXAML 数据网格数据模板
【发布时间】:2012-12-27 16:54:48
【问题描述】:

我正在通过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>

【问题讨论】:

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

标签: xaml windows-8 translate bing-api


【解决方案1】:

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

希望这对其他人也有用。

保罗

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多