Wpf 组合框控件模板下拉按钮

Wpf 组合框控件模板下拉按钮,wpf,combobox,styles,controltemplate,Wpf,Combobox,Styles,Controltemplate,我想知道是否有人举过一个例子,说明如何在组合框的样式/模板中只显示默认初始状态下的按钮。有点像功能区栏的下拉按钮库。我只希望用户能够点击一个按钮,并有组合框项目列出。进行选择时,不会将所选项目保存在文本字段中,因为没有文本字段,只有一个按钮。谢谢:)以下是一些示例代码: 请注意,ContentPresenter和PART_EditableTextBox已被特意注释掉,可以从模板中删除。 此外,您可能需要自定义togglebutton和弹出窗口的外观 <Window x:Class="H

我想知道是否有人举过一个例子,说明如何在组合框的样式/模板中只显示默认初始状态下的按钮。有点像功能区栏的下拉按钮库。我只希望用户能够点击一个按钮,并有组合框项目列出。进行选择时,不会将所选项目保存在文本字段中,因为没有文本字段,只有一个按钮。谢谢:)

以下是一些示例代码:
请注意,ContentPresenter和PART_EditableTextBox已被特意注释掉,可以从模板中删除。
此外,您可能需要自定义togglebutton和弹出窗口的外观

<Window x:Class="HiddenTextComboBox.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <ControlTemplate x:Key="HiddenTextComboBox" TargetType="{x:Type ComboBox}">
            <Grid>
                <ToggleButton x:Name="DropDownToggle"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  
                  Margin="-1" HorizontalContentAlignment="Right"
                  IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,
                              RelativeSource={RelativeSource TemplatedParent}}">
                    <Path x:Name="BtnArrow" Height="4" Width="8" 
                    Stretch="Uniform" Margin="0,0,4,0"  Fill="Black"
                    Data="F1 M 300,-190L 310,-190L 305,-183L 301,-190 Z " />
                </ToggleButton>
                <!--<ContentPresenter x:Name="ContentPresenter" Margin="6,2,25,2"
                  Content="{TemplateBinding SelectionBoxItem}"
                  ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}">
                </ContentPresenter>
                <TextBox x:Name="PART_EditableTextBox"
                  Style="{x:Null}"
                  Focusable="False"
                  Background="{TemplateBinding Background}"
                  HorizontalAlignment="Left" 
                  VerticalAlignment="Center" 
                  Margin="3,3,23,3"
                  Visibility="Hidden"
                  IsReadOnly="{TemplateBinding IsReadOnly}"/>-->
                <Popup x:Name="PART_Popup"
                  IsOpen="{TemplateBinding IsDropDownOpen}">
                    <Border x:Name="PopupBorder" 
                    HorizontalAlignment="Stretch" Height="Auto" 
                    MinWidth="{TemplateBinding ActualWidth}"
                    MaxHeight="{TemplateBinding MaxDropDownHeight}"
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    BorderBrush="Black" Background="White" CornerRadius="3">
                        <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </Border>
                </Popup>
            </Grid>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
            <ComboBox Height="23" Width="23" Template="{StaticResource HiddenTextComboBox}">
                <ComboBoxItem>First</ComboBoxItem>
                <ComboBoxItem>Second</ComboBoxItem>
                <ComboBoxItem>Third</ComboBoxItem>
            </ComboBox>
    </Grid>
</Window>

第一
第二
第三
代码改编自: