我的usercontrol中有几个AutoCompleteBox。单独的框显示白色背景的结果,我认为是默认的。无论出于何种原因,当我在ListBox.ItemContainerStyle中有一个AutoCompleteBox时,弹出窗口的背景为灰色。知道为什么会有所不同吗?
以下是白色的示例代码:
<controls:AutoCompleteBox Grid.Row="6" x:Name="FacilityCompleteBox" TextChanged="FacilityCompleteBox_OnTextChanged" ItemsSource="{Binding}" ValueMemberPath="ListName" SelectedItem="{Binding ElementName=patientVisitControl, Path=ClaimViewModel.SelectedFacility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
LostFocus="CompleteBox_OnLostFocus" Text="{Binding ElementName=patientVisitControl, Path=ClaimViewModel.Visit.Facility.Facility.ListName}">
<controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ListName}" />
</DataTemplate>
</controls:AutoCompleteBox.ItemTemplate>
</controls:AutoCompleteBox>
这是我的列表框,弹出窗口中有灰色背景:
<ListBox x:Name="Resources" Grid.Row="8" ItemsSource="{Binding Path=ClaimViewModel.Claim.PatientVisitResources}" BorderBrush="Transparent" Background="White">
<ListBox.Resources>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ItemsPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<!--<claimOverlay:PopupFilterControl x:Name="ResourceSearchFilter" SearchControlViewModel="{Binding}" ClaimOverlayWindow="{Binding ElementName=patientVisitControl, Path=ClaimOverlayWindow}" Height="30" MaxHeight="30"
DeleteResource="ResourceSearchFilter_OnDeleteResource" SelectCard="Default_OnSelectCard" />-->
<controls:AutoCompleteBox x:Name="ResourceCompleteBox" TextChanged="ResourceCompleteBox_OnTextChanged" ItemsSource="{Binding}" ValueMemberPath="ListName"
LostFocus="CompleteBox_OnLostFocus" Text="{Binding Path=ListName}">
<controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ListName}" />
</DataTemplate>
</controls:AutoCompleteBox.ItemTemplate>
</controls:AutoCompleteBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
我的用户控件中没有ListBox的任何其他样式。
答案 0 :(得分:0)
所以我假设ListBox中的某个样式使其变为灰色,因此使用AutoCompleteBoxes ItemContainerStyle属性创建了以下样式:
<Style x:Key="ListBoxItemContainerStyle" TargetType="ListBoxItem">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
此样式现在将我的列表框弹出背景更改为白色以匹配我控制中的其他AutoCompleteBox。