WPF RichTextBox + StackPanel 中的按钮 =>真是一团糟?

发布于 2024-09-26 15:57:46 字数 467 浏览 6 评论 0原文

此代码:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是在用心讲痛 2024-10-03 15:57:46

您最好使用 Grid 和 RTB 的 Horizo​​ntalAlignment (和 VerticalAlignment)属性。

<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>

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>
飘逸的'云 2024-10-03 15:57:46

你的代码布局应该是这样的:

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

你必须单独调整每个元素(控件)的大小,否则你会得到一个与最初的布局类似的布局(所有元素都混乱并压在一起。)

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.)

千寻… 2024-10-03 15:57:46

抱歉,我忘了提及,如果您查看“布局”面板(对于 RichTextBox),在其底部有一个向下箭头。单击它打开“高级选项”。在那里你想将“Horizo​​ntalContentAlignment 和 VertialContentAlignment”设置为拉伸。 (每个选项最后 2 个)。

我很抱歉忽略了这一点。我的错。 :)

ScreenShot:

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. :)

ScreenShot:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文