0

我的用户控件中有几个 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 样式。

4

1 回答 1

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>

这种风格现在将我的列表框弹出背景改回白色,以匹配我控件中的其他 AutoCompleteBoxes。

于 2013-09-10T13:54:44.533 回答