【问题标题】:WPF DockPanel - order controlsWPF DockPanel - 订单控件
【发布时间】:2012-04-04 21:56:33
【问题描述】:

我想要一个带有行号的文本框。所以我决定用一个小的TextBox作为左边的行号,用另一个大的TextBox作为文本。 我现在的问题是我将这两个 TextBoxes 放入 Dockpanel 中,我需要一个高度差,因为行号的 TextBox 不应该有滚动条。所以我需要缩短左边的TextBox。我的计划是在左侧 TextBox 下方放置一个空 StackPanel。而且我遇到了麻烦,因为 DockPanel 没有按我想要的方式对我的控件进行排序。我得到它的唯一方法是使用固定宽度,但我不想那样!

或者我应该采取完全不同的方式吗?

【问题讨论】:

    标签: c# wpf dockpanel


    【解决方案1】:

    我不知道你为什么要构建这个控件,但是你可以为 WPF 找到类似的东西。请参阅此链接AvalonEdit。这是一个文本编辑器控件。

    【讨论】:

      【解决方案2】:

      如果您不希望控件上有滚动条,只需将 VerticalScrollBarVisibility 设置为禁用即可。

      但我不确定这是否正是您所需要的。如果你这样做,那么显然你的行号不会随着你的文本框滚动。您最好的选择是将您的两个文本框(尽管如果行号不应该是可编辑的,您可能希望使用标签代替)放在一个停靠面板中,并将停靠面板包装在一个滚动查看器中。

      【讨论】:

        【解决方案3】:

        您可以尝试使用 ScrollView。下面的代码演示了这个想法。但是我还没有想出一个启用水平滚动的解决方案。

        <Window x:Class="WpfApplication1.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                Title="MainWindow" Height="350" Width="525">
            <Grid>
                <ScrollViewer Height="100">
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Left">
                            <TextBlock.Inlines>
                                1<LineBreak/>
                                2<LineBreak/>
                                3<LineBreak/>
                                4<LineBreak/>
                                5<LineBreak/>
                                6<LineBreak/>
                                7<LineBreak/>
                                8<LineBreak/>
                                9<LineBreak/>
                                10<LineBreak/>
                                11<LineBreak/>
                                12<LineBreak/>
                                13<LineBreak/>
        </TextBlock.Inlines>
                        </TextBlock>
                        <TextBox AcceptsReturn="True" TextWrapping="Wrap">
                            I want a TextBox with line numbers. So I decided to use one small TextBox for the line numbers on the left and another big one on the rigth for the text. My problem now is that I put these two TextBoxes into a Dockpanel and I need a Heigth difference because the TextBox for the line numbers should not have scrollbars. So I need to short the left TextBox. My plan is to put an empty StackPanel below the left TextBox. And I'm getting trouble because the DockPanel doesen't sort my controls like i want. The only way I got it was using a fix width but I don't want that!
                        </TextBox>
                    </DockPanel>
                </ScrollViewer>
            </Grid>
        </Window>
        

        看起来像

        【讨论】:

        • er...这可能与 Matt Burland 的回答重复...。我没有阅读所有答案。
        猜你喜欢
        • 1970-01-01
        • 2011-12-21
        • 1970-01-01
        • 1970-01-01
        • 2019-12-17
        • 2021-05-13
        • 1970-01-01
        • 2011-04-29
        • 2012-12-01
        相关资源
        最近更新 更多