Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove Control Highlight From ListBoxItems but not children controls
    text
    copied!<p>I am using a ListBox to display a list of items: PictureOrders. I have applied a DataTemplate for the ListBox's Items.</p> <p>I would like to style the list box so that the items are not highlighted when the mouse is over any of the items in the list box and so that the selected item in the list box is not highlighted either.</p> <p>So, I used the following in the ListBox's resources:</p> <pre><code> &lt;ListBox.Resources&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /&gt; &lt;/ListBox.Resources&gt; </code></pre> <p>However, now the ComboBoxes within the ListBox no longer have highlight colors which poses a bit of a problem.</p> <p>I have the following classes:</p> <pre><code>Public Class PictureOrder Public Property OrderName As String Public Property NumberOfPictures As Integer Public Property QualityOfPictures As Integer Public Property Comments As String End Class Public Class PictureOrders Public Property PictureOrders As ObjectModel.ObservableCollection(Of PictureOrder) Public Sub New() PictureOrders = New ObjectModel.ObservableCollection(Of PictureOrder) For i As Integer = 1 To 11 ' Dim picOrder As New PictureOrder With {.OrderName = String.Format("Picture Order # {0}", i.ToString), .NumberOfPictures = 50, .QualityOfPictures = 10, .Comments = String.Format("Picture Order # {0} Comments", i.ToString)} PictureOrders.Add(picOrder) Next End Sub End Class </code></pre> <p>Here is my current XAML:</p> <pre><code>&lt;Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Picture Orders" Height="600" Width="600" xmlns:myProj="clr-namespace:TryingWPF"&gt; &lt;Window.Resources&gt; &lt;x:Array x:Key="NumberOfPicturesOptions" Type="sys:Int32" xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt; &lt;sys:Int32&gt;10&lt;/sys:Int32&gt; &lt;sys:Int32&gt;15&lt;/sys:Int32&gt; &lt;sys:Int32&gt;20&lt;/sys:Int32&gt; &lt;sys:Int32&gt;25&lt;/sys:Int32&gt; &lt;sys:Int32&gt;50&lt;/sys:Int32&gt; &lt;sys:Int32&gt;100&lt;/sys:Int32&gt; &lt;sys:Int32&gt;150&lt;/sys:Int32&gt; &lt;/x:Array&gt; &lt;x:Array x:Key="QualityOfPicturesOptions" Type="sys:Int32" xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt; &lt;sys:Int32&gt;5&lt;/sys:Int32&gt; &lt;sys:Int32&gt;6&lt;/sys:Int32&gt; &lt;sys:Int32&gt;7&lt;/sys:Int32&gt; &lt;sys:Int32&gt;8&lt;/sys:Int32&gt; &lt;sys:Int32&gt;9&lt;/sys:Int32&gt; &lt;sys:Int32&gt;10&lt;/sys:Int32&gt; &lt;/x:Array&gt; &lt;myProj:PictureOrders x:Key="Orders" /&gt; &lt;/Window.Resources&gt; &lt;ListBox x:Name="OrderListings" DataContext="{StaticResource Orders}" ItemsSource="{Binding PictureOrders}" SelectedIndex="0"&gt; &lt;ListBox.Resources&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /&gt; &lt;/ListBox.Resources&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Expander x:Name="PhotoOrderExpander" Content="{Binding}" Header="{Binding OrderName}" IsExpanded="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"&gt; &lt;Expander.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;DockPanel Margin="25,5"&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label VerticalAlignment="Top" Content="Order Name" /&gt; &lt;TextBox Text="{Binding OrderName, ValidatesOnExceptions=True}" VerticalAlignment="Top" MaxLength="50"/&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="NumberOfPictures" /&gt; &lt;ComboBox ItemsSource="{Binding Source={StaticResource NumberOfPicturesOptions}}" SelectedItem="{Binding Path=NumberOfPictures, ValidatesOnExceptions=True}" /&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="Quality Of Pictures" /&gt; &lt;ComboBox ItemsSource="{StaticResource QualityOfPicturesOptions}" SelectedItem="{Binding Path=QualityOfPictures, ValidatesOnExceptions=True}" /&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="Comments" /&gt; &lt;TextBox Text="{Binding Comments}" /&gt; &lt;/DockPanel&gt; &lt;/DockPanel&gt; &lt;/DataTemplate&gt; &lt;/Expander.ContentTemplate&gt; &lt;/Expander&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p></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