Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd rectangle to WPF Listbox and make alternate the fill color of that rectangle
    text
    copied!<p>I have listbox with a TextBlock bound to a field, and the I have set the AlternationCount="2" this works great for changing the background color of the items control; however, I cannot get the effect I want with my rectangle... I'm trying to have a rounded corners effect on each listbox item.</p> <p><strong>edit:</strong> the xaml</p> <pre><code>&lt;DataTemplate x:Key="TaskListTemplate"&gt; &lt;Grid Height="276" Width="Auto"&gt; &lt;Rectangle Fill="Gray" Stroke="Black" RadiusX="8" RadiusY="8" Margin="0"/&gt; &lt;TextBox x:Name="txtDescription" Text="{Binding Path=Des}" /&gt; &lt;TextBox x:Name="txtComments" Text="{Binding Path=Com}"/&gt; &lt;Label Content="{Binding Path=Title}"&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;ListBox Margin="8,37,0,6" ItemContainerStyle="{DynamicResource ListBoxItemStyle}" AlternationCount="2" ItemTemplate="{DynamicResource TaskListTemplate}"/&gt; &lt;Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}"&gt; &lt;Setter Property="FontSize" Value="12" /&gt; &lt;Setter Property="FontFamily" Value="Tahoma" /&gt; &lt;Setter Property="Background" Value="#006C3B3B"/&gt; &lt;Style.Resources&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF533F70"/&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF533F70"/&gt; &lt;Storyboard x:Key="MouseOverStoryBoard"&gt; &lt;ColorAnimationUsingKeyFrames AutoReverse="True" BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00" Value="#FFF48F21"/&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="#FF4A475C"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/Style.Resources&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="ItemsControl.AlternationIndex" Value="0"&gt; &lt;Setter Property="Background"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush Color="#FFA2BAD4"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Foreground" Value="White"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="ItemsControl.AlternationIndex" Value="1"&gt; &lt;Setter Property="Background" Value="#FF7395B9"/&gt; &lt;Setter Property="Foreground" Value="White"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard Storyboard="{StaticResource MouseOverStoryBoard}"/&gt; &lt;/Trigger.EnterActions&gt; &lt;Setter Property="Foreground" Value="White" /&gt; &lt;Setter Property="Background" Value="#FFF48F21"/&gt; &lt;Setter Property="FontStyle" Value="Normal"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload