我是list box
,其中包含一个listboxitem
&此listboxitem
包含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#中动态分配数据(图像源和文本块值),
那我怎样才能访问这个datatemplate
&amp;他的孩子在代码中控制(image
&amp; textblock
),以及如何将此datatemplate
添加到listboxitem
,
对于生成xaml的想法,将会是什么样的---&gt;
<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>
上面的内容