【问题标题】:WPF AutoCompleteBox Popup BackgroundWPF AutoCompleteBox 弹出背景
【发布时间】:2013-09-09 21:05:09
【问题描述】:

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

【问题讨论】:

    标签: wpf popup autocompletebox


    【解决方案1】:

    所以我假设 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。

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 1970-01-01
      • 2010-12-16
      • 2011-07-12
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 1970-01-01
      相关资源
      最近更新 更多