在组合框WPF中的文本下方添加边框

问题描述

我需要在组合框的所有弹出行下方添加一行。 所以现在我有了ComboBox,看起来像这样:

Existing Combobox

并弹出使用此XAML代码实现的行:

          <Popup Name="PART_Popup"
             WindowManagerAddShadowHint="False"
             IsOpen="{TemplateBinding IsDropDownopen,Mode=TwoWay}"
             MinWidth="{Binding Bounds.Width,RelativeSource={RelativeSource TemplatedParent}}"
             MaxHeight="{TemplateBinding MaxDropDownHeight}"
             PlacementTarget="{TemplateBinding}"
             IsLightdismissEnabled="True">
        <Grid>
          <Grid.RowDeFinitions>
            <RowDeFinition Height="*"/>
            <RowDeFinition Height="5*"/>
            <RowDeFinition Height="10*"/>
          </Grid.RowDeFinitions>
          <Border x:Name="PopupBorder"
                  Grid.Row="1"
                  Background="#00A9FF"
                  BorderBrush="Black"
                  BorderThickness="{DynamicResource ComboBoxDropdownBorderThickness}"
                  Margin="0,-1,-1"
                  Padding="0"
                  HorizontalAlignment="Stretch"
                  CornerRadius="0"
                  Grid.Column="2"
                  >
           
            <ScrollViewer>
              <ItemsPresenter Name="PART_ItemsPresenter"
                              Items="{TemplateBinding Items}"
                              Margin="{DynamicResource ComboBoxDropdownContentMargin}"
                              ItemsPanel="{TemplateBinding ItemsPanel}"
                              ItemTemplate="{TemplateBinding ItemTemplate}"
                              VirtualizationMode="{TemplateBinding VirtualizationMode}"
                              />
             
            </ScrollViewer>
            
          </Border>
          
         
        </Grid>
      </Popup>

我需要使ComboBox与此类似:

Desired Combobox

我无法插入其他边框以使线条显示出来,所以我不知道该怎么办。

解决方法

您需要修改ComboBoxItem而不是ComboBox的样式/控件模板。

您可以修改ComboBoxItem的控制模板,并将行放在此处。

另一种选择是为ItemTemplate的样式创建默认的ComboBox,但是开发人员很容易覆盖它。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...