ygoe
ygoe

Reputation: 20414

Align TextBox inside a TextBlock

I want to display a short sentence with a TextBox control in the middle of wrapping text where the user shall enter a value. I'm not sure whether it's a good idea to do this:

<TextBlock TextWrapping="Wrap">
    <Run Text="Keep at least"/>
    <TextBox Width="30" Margin="4,0"/>
    <Run Text="MB free on the drive"/>
</TextBlock>

But it works and wraps the input field along with the text. Unfortunately, the TextBox is baseline-aligned with the text, not centered. This means that the text within the input box is not on the same height as the label around it. Obvious vertical alignment attributes don't help me.

Is there any solution to this, or a different method altogether?

HTML can do this just fine, how about WPF?

Upvotes: 3

Views: 1563

Answers (1)

Szabolcs D&#233;zsi
Szabolcs D&#233;zsi

Reputation: 8843

I think this should help.

<TextBlock TextWrapping="Wrap">
    <Run Text="Keep at least"/>
    <InlineUIContainer BaselineAlignment="Center">
        <TextBox Width="30" Margin="4,0"/>
    </InlineUIContainer>
    <Run Text="MB free on the drive"/>
</TextBlock>

Upvotes: 8

Related Questions