Anchor a TextBox to the right and Left (so it’s stretched when parent is resized)

坚强是说给别人听的谎言 提交于 2019-12-11 10:51:32

问题


I’m looking for the XAML equivalent of Winforms’ Anchor property. I want to anchor a TextBox that’s on a Canvas (on a UWP app) to the left and right so it’s always 260 from the left and 10 from the right. I’ve tried many things, but the one that looks most promising was:

<TextBox Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  TextWrapping="Wrap" Text="TextBox"  Margin="260,10,10,10"/>

It does not, however anchor to the right.


回答1:


I would use a 3-column Grid.

<Grid x:Name="YourOuterGrid">
    <Grid VerticalAlignment="Top">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="160" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <TextBox TextWrapping="Wrap" Grid.Column="1" />
    </Grid>
</Grid>


来源:https://stackoverflow.com/questions/32362064/anchor-a-textbox-to-the-right-and-left-so-it-s-stretched-when-parent-is-resized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!