I have a control with a ListBox like this:
<local:MyControl x:Name="LayoutRoot" ...>
<local:MyControl.Resources>
<ItemsPanelTemplate x:Key="myTemplate">
<StackPanel Background="Yellow"/>
</ItemsPanelTemplate>
</local:MyControl.Resources>
<Border>
...
<ListBox ItemsPanel="{DynamicResource myTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
<Rectangle Height="50" Width="200" Margin="10" Fill="Red"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
...
</Border>
</local:MyControl>
This is how it looks like when I run it:

The ListBox paints a "frame" around each items based on their state:
- Not selected: transparent
- Selected and ListBox is in focus: blue
- Selected and ListBox is out of focus: white
I guess the "frame" is the visible part of the background of the ListBoxItem under the Margin of the Rectangle object, but I am not sure.
I would like to customize the look of the "frame"-s for each different state. Could you give me an example how to do that?