How do I bind list items to an Accordian control from the Silverlight 3 Toolkit?

Posted by Blanthor on Stack Overflow See other posts from Stack Overflow or by Blanthor
Published on 2010-03-14T14:29:46Z Indexed on 2010/03/14 14:35 UTC
Read the original article Hit count: 638

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.

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about silverlight-3.0