0

现在我正在创建一个 gridview,我想用从 textbox 生成的字符串项填充这个网格视图,但是使用我自己的 GridviewItem 模板,我如何将 gridviewitem 模板中的文本块与从文本框中添加的字符串绑定

private void onTapped(object sender, TappedRoutedEventArgs e)
{
    Taglist.Items.Add(tagBox.Text);         
    tagBox.Text = "";
}

这是 Xaml :

<DataTemplate x:Key="listitemTemplate">
        <Grid Height="164" Width="651">
            <Grid.Background>
                <ImageBrush ImageSource="Assets/new design/tags.PNG"/>
            </Grid.Background>
            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Text}" VerticalAlignment="Top" Margin="136,49,0,0" Height="69" Width="406" FontSize="48"   />
        </Grid>
</DataTemplate>
4

1 回答 1

0

ok I found my mistake , I should write in the binding , Text = "{Binding}" that's it

the correct xaml is :

<DataTemplate x:Key="listitemTemplate"> 
    <Grid Height="164" Width="651"> 
        <Grid.Background> 
            <ImageBrush ImageSource="Assets/new design/tags.PNG"/> 
        </Grid.Background> 
        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding}" 
            VerticalAlignment="Top" Margin="136,49,0,0" Height="69" Width="406" FontSize="48" /> 
    </Grid> 
</DataTemplate>
于 2013-01-26T18:09:14.857 回答