我想要一个带行号的TextBox。所以我决定使用一个小的TextBox作为左侧的行号,右侧的另一个大的TextBox用于文本。 我现在的问题是我将这两个TextBox放入Dockpanel并且我需要一个高度差,因为行号的TextBox不应该有滚动条。所以我需要缩短左边的TextBox。我的计划是在左侧TextBox下面放置一个空的StackPanel。我遇到了麻烦,因为DockPanel没有像我想的那样对控件进行排序。我得到它的唯一方法是使用固定宽度,但我不希望这样!
或者我应该采用完全不同的方式?
答案 0 :(得分:1)
我不知道为什么你必须构建这个控件,但你可以找到类似的WPF。请参阅此链接AvalonEdit。这是一个文本编辑器控件。
答案 1 :(得分:0)
如果您不想在控件上使用滚动条,只需将VerticalScrollBarVisibility设置为disabled。
但我不确定这正是你所需要的。如果你这样做,那么显然你的行号不会随你的文本框一起滚动。您最好的选择可能是将两个文本框(尽管行号不应该是可编辑的,您可能希望使用标签代替)在dockpanel中并将停靠面板包装在滚动查看器中。
答案 2 :(得分:0)
您可以尝试使用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>
看起来像