我有一个列表框,它使用itemtemplate来显示图像。我希望能够更改itemtemplate中显示图像的大小。通过数据绑定,我可以更改宽度,但我能看到的唯一方法是向我绑定的类添加一个属性(比如imagesize),然后将集合中的每个项更改为具有新的imagesize。是否无法访问该数据模板中某个项的属性?
例如。
<navigation:Page.Resources>
<DataTemplate x:Key="ListBoxItemTemplate">
<Viewbox Height="100" Width="100">
<Image Source="{Binding Image}"/>
</Viewbox>
</DataTemplate>
</navigation:Page.Resources>
<Grid>
<ListBox ItemTemplate="{StaticResource ListBoxItemTemplate}" ItemSource="{Binding Collection}"/>
</Grid>
是否仍要设置ViewBox的宽度和高度,而不将属性绑定到集合中的每个元素?