i'v a list box,其中包含一个listboxitem& 这listboxitem包含 a wrap panel,我想在其中添加grids(包含用户个人资料图片和名称),以便我创建一个datatemplate--->
<DataTemplate x:Key="UserGridListTemplate">
<Grid Height="140" Width="155">
<Grid.Background>
<ImageBrush ImageSource="{Binding UPicPath}" Stretch="Fill"/>
</Grid.Background>
<TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" Text="{Binding UName}" Foreground="Black" FontSize="27" OpacityMask="#7C000000" />
</Grid>
</DataTemplate>
我想在 c# 中动态分配数据(图像源和 texblock 值),那么我如何在代码中访问这个datatemplate和他的子控件(image& textblock),以及如何将这个datatemplate添加到那个listboxitem,
对于生成 xaml 的想法会是什么样子--->
<Grid Grid.RowSpan="5" Width="334" Grid.ColumnSpan="2" Margin="134,80,-12,20">
<ListBox>
<ListBoxItem>
<toolkit:WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top">
// -->UserGridListTemplate instance 1 with some data assigned
// -->UserGridListTemplate instance 1 with some data assigned
// -->UserGridListTemplate instance 1 with some data assigned
and so on................
</toolkit:WrapPanel>
</ListBoxItem>
</ListBox>
</Grid>
看起来像上面的东西