StackPanel 中的 WPF RichTextBox + 按钮 =>真是一团糟? [英] A WPF RichTextBox + Button in a StackPanel => what a mess?
本文介绍了StackPanel 中的 WPF RichTextBox + 按钮 =>真是一团糟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码:
<StackPanel Orientation="Horizontal">
<RichTextBox />
<Button Content="Dialog" />
</StackPanel>
在 StackPanel 左侧某处显示按钮到 RichTextBox 上,为什么?
shows the button somewhere on the left side of the StackPanel ONTO the RichTextBox, WHY?
哦,我刚刚看到它的宽度问题.RTB 几乎没有宽度,按钮位于其右侧.
edit: Oh I just saw its a width problem. The RTB has nearly no width and the button is righthand of it.
似乎我遇到了这个错误:WPF RichTextBox 没有设置宽度一个>
edit: seems I run into this bug: WPF RichTextBox with no width set
解决方案对我不起作用!
solution does not work for me!
推荐答案
最好使用 Grid 和 RTB 的 HorizontalAlignment(和 VerticalAlignment)属性.
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>
这篇关于StackPanel 中的 WPF RichTextBox + 按钮 =>真是一团糟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文