开发者

Silverlight - Auto-resize textbox to fill up empty space

Ok this is what I wish to do.

I have a resizeable window which has 3 controls in same row in flowing order: textBlock, textBox and button.

textBlock and button have dynamic texts. So theirs size depends upon text inside.

Now what I wish to do is that textBox in the middle is always filling up all empty space between textBlock and button.

How do I do that?

I tried with the following code but it doesn't work because of fixed width in 1. and 3. column.

<Grid Margin="0,0,5,0" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="40"/> 
    </Grid.ColumnDefinitions>                                
    <TextBlock Grid.Column="开发者_运维百科0" HorizontalAlignment="Left" Text="Text1"/>
    <TextBox Grid.Column="1"/>
    <Button Grid.Column="2" Content="Button1" HorizontalAlignment="Center"/>
</Grid>


You can use Auto for the two outer column widths instead of specifying the width

<Grid Margin="0,0,5,0" > 
    <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="Auto" /> 
        <ColumnDefinition Width="*" /> 
        <ColumnDefinition Width="Auto" />  
    </Grid.ColumnDefinitions>                                 
    <TextBlock Grid.Column="0" Text="Text1" /> 
    <TextBox Grid.Column="1"/> 
    <Button Grid.Column="2" Content="Button1" /> 
</Grid>

You probably don't need the HorizontalAlignment in the columns either

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜