Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this:</p> <pre><code>&lt;Window.Resources&gt; &lt;SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" /&gt; &lt;SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" /&gt; &lt;SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" /&gt; &lt;!-- SimpleStyles: ListBoxItem --&gt; &lt;Style TargetType="ListBoxItem" x:Key="ListBoxItemTemplate"&gt; &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt; &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBoxItem"&gt; &lt;Grid&gt; &lt;Rectangle x:Name="Rectangle" Fill="Transparent" Stroke="Black" StrokeDashCap="Square" StrokeThickness="0" SnapsToDevicePixels="True"&gt; &lt;Rectangle.StrokeDashArray&gt; &lt;sys:Double&gt;5&lt;/sys:Double&gt; &lt;/Rectangle.StrokeDashArray&gt; &lt;/Rectangle&gt; &lt;Border Name="Border" Padding="2" BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}" BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"&gt; &lt;ContentPresenter /&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSelected" Value="true"&gt; &lt;Setter TargetName="Rectangle" Property="StrokeThickness" Value="1" /&gt; &lt;Setter TargetName="Border" Property="BorderThickness" Value="0" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsSelected" Value="true"&gt; &lt;Setter TargetName="Rectangle" Property="Fill" Value="{StaticResource SelectedBackgroundBrush}" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource ListBoxItemTemplate}"&gt; &lt;Setter Property="Height" Value="30" /&gt; &lt;Setter Property="BorderThickness" Value="0,0,0,1" /&gt; &lt;Setter Property="BorderBrush" Value="Silver" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="ItemsControl.AlternationIndex" Value="3"&gt; &lt;Setter Property="BorderBrush" Value="Black"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;StackPanel&gt; &lt;ListBox&gt; &lt;ListBoxItem Content="Item 1" /&gt; &lt;ListBoxItem Content="Item 2" /&gt; &lt;ListBoxItem Content="Item 3" /&gt; &lt;ListBoxItem Content="Item 4" /&gt; &lt;/ListBox&gt; &lt;/StackPanel&gt; </code></pre> <p>So I put a rectangle bellow the actual border in the control template. The rectangle can have its border be dotted, or dashed or w/e (to make the dash smaller just change the part to 2, 1 is not noticeable). So the default value of the rectangle's border thickness is 0, but when selected I set the thickness to 1 so it's visible. I made some border properties to be binded to its templated parent too, so it can look like what you set on your style (brush silver, thickness 0,0,0,1).</p>
 

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