WPF 中组合框上的文本框

发布于 2025-01-03 07:38:21 字数 274 浏览 3 评论 0原文

<Grid>
    <ComboBox Name="comboBox1" />
    <TextBox Name="TextBox1" />
</Grid>

在我的 wpf 应用程序中,我想在组合框上显示一个文本框,但我不知道如何维护文本框大小,以便它只覆盖组合框的框部分,而不覆盖组合框的向下箭头部分?

像这样

<Grid>
    <ComboBox Name="comboBox1" />
    <TextBox Name="TextBox1" />
</Grid>

In my wpf application I want to display a textbox on a combobox but i don't know how to maintain textbox size so that it only covers the box part of the combobox and not the down arrow part of combobox?

like this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷港 2025-01-10 07:38:21

您可以这样做:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="119*" />
            <ColumnDefinition Width="17" />
        </Grid.ColumnDefinitions>
        <ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" Width="134" Grid.ColumnSpan="2" />
        <TextBox Name="textBox1" Margin="0,0,0,3" />
    </Grid>

关键是将网格的第二列设置为固定大小,其中该固定大小表示箭头的可见性。

不过,就像其他人提到的那样,最好的办法是将组合框的 IsEditable 属性设置为 true:

<ComboBox Name="combobox1" LostFocus="LostFocus" IsEditable="True"/>

有关详细信息,请参阅此处:WPF 组合框 - 可编辑

You can do it like:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="119*" />
            <ColumnDefinition Width="17" />
        </Grid.ColumnDefinitions>
        <ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" Width="134" Grid.ColumnSpan="2" />
        <TextBox Name="textBox1" Margin="0,0,0,3" />
    </Grid>

The key thing is to set the grid's second column to a fixed size, where that fixed sized represents the visibility of the arrow.

though, like others have mentioned, the best thing to do is set the combobox's IsEditable property to true:

<ComboBox Name="combobox1" LostFocus="LostFocus" IsEditable="True"/>

for more info, see here: WPF ComboBox - IsEditable

浮光之海 2025-01-10 07:38:21

我认为没有充分的理由将文本框放置在组合框上,因为组合框本身是可编辑的。

但您可以做的是,将组合框分成两个网格列,后面的列固定大小,包括组合框的箭头部分,前一列星形大小。让组合框的列跨度为 2,文本框为 1。

希望有帮助

I don't see a good reason to place a textbox over a combobox, as combobox itself is editable.

But what you can do is, divide your combobox in two gridcolums with later column being fixed sized includeing the arrow part of combobox and former column being star sized. Let combobox have columnspan of 2 and textbox of 1.

hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文