Is there any way to programitically change a Data/ItemTemplate in Silverlight?
Posted
by Kris Erickson
on Stack Overflow
See other posts from Stack Overflow
or by Kris Erickson
Published on 2010-04-15T18:25:50Z
Indexed on
2010/04/21
7:33 UTC
Read the original article
Hit count: 371
So I have a Listbox, which is using an ItemTemplate to display an image. I want to be able to change the size of the displayed image in the ItemTemplate. Through databinding I can change the Width, but the only way I can see how to do this is to add a Property (Say, ImageSize) to the class I am binding to and then change every item in the colleciton to have a new ImageSize. Is there no way to access the property of an item in that Datatemplate?
E.g.
<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>
Is there anyway to set the Width and Height of the viewbox without binding a property to every element in the collection?
© Stack Overflow or respective owner