Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Moore's answer doesn't work, and the page here:</p> <p><a href="http://blogs.msdn.com/b/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx" rel="nofollow noreferrer">Specifying the Selection Color, Content Alignment, and Background Color for items in a ListBox</a></p> <p>explains why it cannot work.</p> <p>If your listview only contains basic text, the simplest way to solve the problem is by using transparent brushes.</p> <pre><code>&lt;Window.Resources&gt; &lt;Style TargetType="{x:Type ListViewItem}"&gt; &lt;Style.Resources&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#00000000"/&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#00000000"/&gt; &lt;/Style.Resources&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; </code></pre> <p>This will produce undesirable results if the listview's cells are holding controls such as comboboxes, since it also changes their color. To solve this problem, you must redefine the control's template.</p> <pre><code> &lt;Window.Resources&gt; &lt;Style TargetType="{x:Type ListViewItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ListViewItem}"&gt; &lt;Border SnapsToDevicePixels="True" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"&gt; &lt;GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Columns="{TemplateBinding GridView.ColumnCollection}" Content="{TemplateBinding Content}"/&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Window.Resources&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