How do I bind list items to an Accordian control from the Silverlight 3 Toolkit?
- by Blanthor
I have a list of objects in a model
public class AccordianModel
{
public List<AccordianItem> Items { get; set; }
public AccordianModel()
{
Items = new List<AccordianItem>
{
new AccordianItem() {Title = "Monkey", ImageUri = "Images/monkey.jpg"},
new AccordianItem() {Title = "Cow", ImageUri = "Images/cow.jpg"},
};
}
}
I want to show the image in the background image of AccordianItems
If I hard code it, it looks like this...
<layoutToolkit:AccordionItem x:Name="Item2" Header="Item 2" Margin="0,0,10,0" AccordionButtonStyle="{StaticResource AccordionButtonStyle1}" ExpandableContentControlStyle="{StaticResource ExpandableContentControlStyle1}" HeaderTemplate="{StaticResource DataTemplate1}" BorderBrush="{x:Null}" ContentTemplate="{StaticResource CarouselContentTemplate}">
<layoutToolkit:AccordionItem.Background>
<ImageBrush ImageSource="Images/cow.jpg" Stretch="None"/>
</layoutToolkit:AccordionItem.Background>
</layoutToolkit:AccordionItem>
When I try it with a binding like <ImageBrush ImageSource="{Binding Path={StaticResource MyContentTemplate.ImageUri}}" Stretch="None"/> or if I try it with <ImageBrush ImageSource="{Binding Path=Items[0].ImageUri}" Stretch="None"/>
, it throws XamlParseException. I haven't seen enough Silverlight yet and I cannot find a close enough example that it makes sense to me.