【发布时间】:2011-08-28 23:47:33
【问题描述】:
<ListBox Name="DisplayItemListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem >
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Response}" />
<Button Width="50" Height="50" Content="Remove" Click="Request_Remove_Click"/>
<Image Name="MyImage" Width="50" Height="50" />
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我像这样在代码隐藏中绑定:
DisplayItemListBox.ItemsSource = (List<MyObject>) MyObjectList;
MyObject 有一个二进制 Photo 属性,我需要在后面的代码中将其转换为 BitmapImage。我需要以这样的方式修改我的 XAML,当 ListBoxItems 首次使用数据初始化时,会命中一个可以访问 ListBoxItem 的 MyObject 和它的 MyImage 的函数。
【问题讨论】:
标签: c# wpf data-binding listbox