我有一个System.Windows.Controls.Image
数组,我将其分配给ListBox.ItemsSource
。
更重要的是,我希望每个Border
周围都有一个Image
。
下面的xaml展示了我的想法。
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="2" Style="{StaticResource borderStyle}"
Child="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如您所知,儿童不是依赖财产;代码不起作用。
那么我应该如何将Image(或ListBox项目)放在模板中?
答案 0 :(得分:2)
ContentControl
应该可以解决问题:
<Border BorderThickness="2" Style="{StaticResource borderStyle}">
<ContentControl Content="{Binding}"/>
</Border>