简体   繁体   中英

How to make a WPF TextBox fill all available space between two buttons ?

I'm trying to make a WPF TextBox fill all available space between two buttons. For some reason the code below does not what I'm trying to achieve

<DockPanel  Height="48" LastChildFill="False">
    <Button DockPanel.Dock="Left">
        <Image Source="Images\large_load.png"></Image>
    </Button>
    <Button DockPanel.Dock="Left">
        <Image Source="Images\large_reload.png"></Image>
    </Button>
    <TextBox Height="24" HorizontalAlignment="Stretch" DockPanel.Dock="Left"></TextBox>
    <Button DockPanel.Dock="Right" Width="48">
        <Image Source="Images\large_delete.png"></Image>
    </Button>
</DockPanel>

The TextBox is not stretched.

Another problem is that when text is added, the textbox width increases and eventually it pushes the right button out of the visible space.

Don't set LastChildFill to false and make the TextBox the last child (by moving the element to the bottom in the code).

(Or use a proper control, like a Grid )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM