This code:
<StackPanel Orientation="Horizontal">
<RichTextBox />
<Button 开发者_如何转开发Content="Dialog" />
</StackPanel>
shows the button somewhere on the left side of the StackPanel ONTO the RichTextBox, WHY?
edit: Oh I just saw its a width problem. The RTB has nearly no width and the button is righthand of it.
edit: seems I run into this bug: WPF RichTextBox with no width set
solution does not work for me!
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. :)
精彩评论