Here’s my XAML:
<ListBox
Name="PlaylistListBox"
ScrollViewer.CanContentScroll="False"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource ResourceKey=MyListBoxView}}"
ItemTemplateSelector="{Binding Source={StaticResource ResourceKey=MySelector}}"
MouseDoubleClick="PlaylistListBox_MouseDoubleClick" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border
Name="Border"
CornerRadius="4"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="Black" />
<!-- The following setter for opacity is giving me headaches -->
<Setter TargetName="Border" Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter
Event="Loaded"
Handler="PlaylistListBoxItem_Loaded" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Two issues:
- Because of the
Opacitysetter, whole item is transparent by 50%. I want just the
border defined in theListBoxItemControlTemplateto be transparent and its content
to preserve full opacity. - How do I make a Setter/Trigger to make that same border red when the
ListBoxis not
in focus? It should be something likeInFocus="False"andIsSelected="True".
Thanks for clarifying.
You should place another border underneath the content and make it half-transparent remaining the main content fully visible. You can accomplish this by using
Gridand placing a “background” border in it first and then the content. This way you will set the opacity only on the background border, but not on the content;You can use a
MultiTriggerfor that.Here is the modified style that shows what I mean: