C# 单击组合框的文本框部分

C# 单击组合框的文本框部分,c#,wpf,xaml,combobox,textbox,C#,Wpf,Xaml,Combobox,Textbox,我们的组合框样式如下: <Style x:Key="OurComboBox" TargetType="ComboBox"> <!-- omitted style Properties --> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox">

我们的组合框样式如下:

<Style x:Key="OurComboBox" TargetType="ComboBox">
    <!-- omitted style Properties -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <ToggleButton Name="ToggleButton"
                                      Grid.Column="2"
                                      ClickMode="Press"
                                      Focusable="false"
                                      IsChecked="{Binding Path=IsDropDownOpen,
                                                          Mode=TwoWay,
                                                          RelativeSource={RelativeSource TemplatedParent}}"
                                      Style="{StaticResource ComboBoxToggleButton}" />
                        <ContentPresenter Name="ContentSite"
                                          Margin="3,3,23,3"
                                          HorizontalAlignment="Left"
                                          VerticalAlignment="Center"
                                          Content="{TemplateBinding SelectionBoxItem}"
                                          ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                          IsHitTestVisible="False" />
                        <TextBox x:Name="PART_EditableTextBox"
                                 Margin="5,3,23,1"
                                 HorizontalAlignment="Left"
                                 VerticalAlignment="Center"
                                 Background="Transparent"
                                 Focusable="False"
                                 FontFamily="Arial Narrow"
                                 FontWeight="DemiBold"
                                 Foreground="#FF404040"
                                 IsReadOnly="True"
                                 PreviewMouseDown=""
                                 Style="{x:Null}"
                                 Template="{StaticResource ComboBoxTextBox}"
                                 Text="{TemplateBinding Text}"
                                 Visibility="Hidden" />

            <!-- omitted PopUp and ControlTemplate.Triggers -->

基于此,我们有了另一种更具体的风格

 <Style x:Key="comboBoxSpecialPage"
           BasedOn="{StaticResource OurComboBox}"
           TargetType="ComboBox">
        <Style.Triggers>
            <Trigger Property="SelectedIndex" Value="-1">
                <Setter Property="Text" Value="Select value" />
            </Trigger>
        </Style.Triggers>
    </Style>

如果组合框中未选择任何内容(例如,在应用程序启动时),则会显示文本“选择值”

但是当我直接点击文本框文本时,什么也没发生

因此,问题是: 如何实现弹出窗口的打开,就像其他窗口打开时一样 是否单击组合框(没有文本的部分)

-编辑-
如果我遗漏了感兴趣的部分,请告诉我,我会添加它们。

也许您正在寻找的是IshitteVisible属性,更多信息如下:

ComboBox有一个名为DropDownStyle的属性。
将此设置为DropDownList,文本区域将不再可编辑,即您必须从列表中进行选择。

是否确实要实现此行为?关于可用性,这是一个奇怪的解决方案,因为你有一个用户操作和两个期望的行为。如果我使用
组合框
,我希望选择我正在单击的项目。我不希望
文本框
切换到编辑模式。我希望组合框像组合框一样工作。我不希望文本框部分是可编辑的,它应该显示一些文本。如果在文本框中单击,则会弹出组合框。现在,情况并非如此。如果单击文本未覆盖的区域,则会弹出该窗口。我怎样才能使它在点击文本时弹出?啊,对不起,现在我明白了你的问题。它是一个System.Windows.Controls.ComboBox。认为是没有这样的属性。对不起我的不好。我在想System.Windows.Forms.ComboBox。抱歉,我迟了回答。试着处理那处房产,但到目前为止没有成功。好了,现在它开始工作了!必须设置
ishitestvisible=“False”
IsEnabled=“False”
。非常感谢你!