我正在使用 ListBox 来显示项目列表:PictureOrders。我为 ListBox 的项目应用了 DataTemplate。
我想设置列表框的样式,以便当鼠标悬停在列表框中的任何项目上时不会突出显示这些项目,并且列表框中的选定项目也不会突出显示。
因此,我在 ListBox 的资源中使用了以下内容:
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</ListBox.Resources>
但是,现在 ListBox 中的 ComboBoxes 不再具有突出显示的颜色,这会带来一些问题。
我有以下课程:
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
这是我当前的 XAML:
<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">
<Window.Resources>
<x:Array x:Key="NumberOfPicturesOptions" Type="sys:Int32"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Int32>10</sys:Int32>
<sys:Int32>15</sys:Int32>
<sys:Int32>20</sys:Int32>
<sys:Int32>25</sys:Int32>
<sys:Int32>50</sys:Int32>
<sys:Int32>100</sys:Int32>
<sys:Int32>150</sys:Int32>
</x:Array>
<x:Array x:Key="QualityOfPicturesOptions" Type="sys:Int32"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Int32>5</sys:Int32>
<sys:Int32>6</sys:Int32>
<sys:Int32>7</sys:Int32>
<sys:Int32>8</sys:Int32>
<sys:Int32>9</sys:Int32>
<sys:Int32>10</sys:Int32>
</x:Array>
<myProj:PictureOrders x:Key="Orders" />
</Window.Resources>
<ListBox x:Name="OrderListings" DataContext="{StaticResource Orders}" ItemsSource="{Binding PictureOrders}" SelectedIndex="0">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<Expander x:Name="PhotoOrderExpander"
Content="{Binding}"
Header="{Binding OrderName}"
IsExpanded="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}">
<Expander.ContentTemplate>
<DataTemplate>
<DockPanel Margin="25,5">
<DockPanel DockPanel.Dock="Top">
<Label VerticalAlignment="Top" Content="Order Name" />
<TextBox Text="{Binding OrderName, ValidatesOnExceptions=True}" VerticalAlignment="Top" MaxLength="50"/>
</DockPanel>
<DockPanel DockPanel.Dock="Top">
<Label Content="NumberOfPictures" />
<ComboBox ItemsSource="{Binding Source={StaticResource NumberOfPicturesOptions}}"
SelectedItem="{Binding Path=NumberOfPictures, ValidatesOnExceptions=True}" />
</DockPanel>
<DockPanel DockPanel.Dock="Top">
<Label Content="Quality Of Pictures" />
<ComboBox ItemsSource="{StaticResource QualityOfPicturesOptions}"
SelectedItem="{Binding Path=QualityOfPictures, ValidatesOnExceptions=True}" />
</DockPanel>
<DockPanel DockPanel.Dock="Top">
<Label Content="Comments" />
<TextBox Text="{Binding Comments}" />
</DockPanel>
</DockPanel>
</DataTemplate>
</Expander.ContentTemplate>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>