开发者

WPF DropShadowEffect in ListBox

开发者 https://www.devze.com 2023-02-01 13:23 出处:网络
Basically, I have a listboxwhich contains a set of listboxitem (stacked horizontally). On selected listboxitem, there will be dropshadoweffect applied to the border of the listboxitem.

Basically, I have a listbox which contains a set of listboxitem (stacked horizontally). On selected listboxitem, there will be dropshadoweffect applied to the border of the listboxitem.

The problem i am having at the moment is the dropshadopeffect on the left hand side is covering (on top of) the lef开发者_如何学Pythont listboxitem. This is fine for me, however the dropshadoweffect on the right hand side of the listboxitem is covered by (below) the right listboxitem.

Is there a way to make them consistent? so that both sides' dropshadoweffect will appear on top of the left and right listboxitems.


For the selected item you need to set its Panel.ZIndex attached property to 1. If you're retemplating the ListBoxItem, this can be done in xaml with something like:

<ControlTemplate TargetType=”ListBoxItem”>
    <Border x:Name=”Root” BorderBrush=”#bdc1a3” BorderThickness=”1” CornerRadius=”5”     Background=”{StaticResource NormalBrush}”>
        <ContentPresenter Content=”{TemplateBinding Content}” ContentTemplate=”{TemplateBinding  ContentTemplate}” HorizontalAlignment=”Center” VerticalAlignment=”Center” />
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property=”IsSelected” Value=”True”>
            <Setter Property=”Panel.ZIndex” Value=”1” />
            <Setter Property=”BorderBrush” Value=”#2a849d” TargetName=”Root” />
            <Setter Property=”Background” Value=”{StaticResource SelectedBrush}” TargetName=”Root” />
    </ControlTemplate.Triggers>
</ControlTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号