1

I have an array of System.Windows.Controls.Image and I assign it to ListBox.ItemsSource.

What's more, I want to have a Border around each Image.

The xaml below demonstrates my idea.

<ListBox>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="2" Style="{StaticResource borderStyle}"
                    Child="{Binding}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

As you know, Child is not a dependency property; the code won't work.

So how should I put the Image (or the ListBox item) in the template?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86

1 Answers1

2

A ContentControl should do the trick:

<Border BorderThickness="2" Style="{StaticResource borderStyle}">
  <ContentControl Content="{Binding}"/>
</Border>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
ColinE
  • 68,894
  • 15
  • 164
  • 232