WPF RichTextBox + StackPanel 中的按钮 =>真是一团糟?
此代码:
<StackPanel Orientation="Horizontal">
<RichTextBox />
<Button Content="Dialog" />
</StackPanel>
在 RichTextBox 上的 StackPanel 左侧某处显示按钮,为什么?
编辑:哦,我刚刚看到它的宽度问题。 RTB 几乎没有宽度,按钮位于其右侧。
编辑:似乎我遇到了这个错误: WPF RichTextBox with no width set
解决方案对我不起作用!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您最好使用 Grid 和 RTB 的 HorizontalAlignment (和 VerticalAlignment)属性。
You'd be better off using a Grid and the HorizontalAlignment (and VerticalAlignment) properties of the RTB.
你的代码布局应该是这样的:
你必须单独调整每个元素(控件)的大小,否则你会得到一个与最初的布局类似的布局(所有元素都混乱并压在一起。)
Your code layout should be something like:
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.)
抱歉,我忘了提及,如果您查看“布局”面板(对于 RichTextBox),在其底部有一个向下箭头。单击它打开“高级选项”。在那里你想将“HorizontalContentAlignment 和 VertialContentAlignment”设置为拉伸。 (每个选项最后 2 个)。
我很抱歉忽略了这一点。我的错。 :)
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. :)