A WPF RichTextBox + Button in a StackPanel => what a mess?

ⅰ亾dé卋堺 提交于 2019-12-02 02:08:56

You'd be better off using a Grid and the HorizontalAlignment (and VerticalAlignment) properties of the RTB.

<Grid HorizontalAlignment="Stretch"
      VerticalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <RichTextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    <Button Grid.Column="1" 
            Content="Dialog" 
            HorizontalAlignment="Right" 
            VerticalAlignment="Bottom" />
</Grid>

Your code layout should be something like:

<StackPanel Margin="105,73,124,54" Orientation="Horizontal">
                <RichTextBox Width="312" />
                <Button Content="Dialog" VerticalAlignment="Bottom" Height="56" />  
            </StackPanel>

You have to size each element (control) individually, otherwise you get a layout similar to what you have originally (all jumbled up and crushed together.)

Sorry, I forgot to mention, if you look at the "Layout" panel (For the RichTextBox), at the bottom of it, there is a down arrow. click it to open the "advanced options". In there you want to set your "HorizontalContentAlignment and VertialContentAlignment" both to stretch. (The last 2 options for each).

I am sorry for leaving that out. my bad. :)

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