Answer the question
In order to leave comments, you need to log in
How to make the background transparency of list items in Wpf?
Learning Wpf - ran into a problem. The search did not help because I have no idea where to dig.
The idea is this: Each element of the list is highlighted in a different color depending on the contents of one of the columns, and the even (odd) element of the list has a greater (less) transparency than the odd (even).
Here is my attempt. (In this case, of course, the transparency of the entire element changes along with the text, but only the background is needed.)
<Style x:Key="DropedItem" TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
<DataTrigger Binding="{Binding [address-list]}" Value="plain-tarif">
<Setter Property="Background" Value="#B857DA1A" />
<Setter Property="Foreground" Value="#FF151515"/>
</DataTrigger>
<DataTrigger Binding="{Binding [address-list]}" Value="drop-user">
<Setter Property="Background" Value="#B8DA1A1A" />
<Setter Property="Foreground" Value="White"/>
</DataTrigger>
<DataTrigger Binding="{Binding [address-list]}" Value="admin">
<Setter Property="Background" Value="#B8DAAE1A" />
<Setter Property="Foreground" Value="#FF151515"/>
</DataTrigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Opacity" Value="0.5"/>
</Trigger>
</Style.Triggers>
</Style>
Answer the question
In order to leave comments, you need to log in
I'm afraid that some triggers can not do. You can solve it by overriding the ControlTemplate and moving the trigger into it, like so:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid>
<Rectangle x:Name="Background" Fill="{TemplateBinding Background}" />
<GridViewRowPresenter />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter TargetName="Background" Property="Opacity" Value="0.5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Rewrite the Setters in the right places like this:
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#DAAE1A" Opacity="0.5"/>
</Setter.Value>
</Setter>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question