来自文本框的gridviewitem

时间:2013-01-26 18:06:42

标签: c# wpf windows windows-8

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

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>

1 个答案:

答案 0 :(得分:0)

好吧我发现了我的错误,我应该写一下绑定,Text = "{Binding}"就是它

正确的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}" 
            VerticalAlignment="Top" Margin="136,49,0,0" Height="69" Width="406" FontSize="48" /> 
    </Grid> 
</DataTemplate>