WPF DockPanel - 订单控件

WPF DockPanel - 订单控件

问题描述:

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

image

或者我应该去一个完全不同的方式?

如果您不想在控件上使用滚动条,只需将VerticalScrollBarVisibility设置为禁用。

但我不确定那正是您需要的。如果你这样做,那么显然你的行号不会随着你的文本框滚动。最好的办法可能是在DockPanel中放置两个文本框(但如果行号不应该是可编辑的,则可能需要使用标签),并将停靠面板包裹在滚动查看器中。

我不知道为什么你必须建立这个控件,但你可以找到类似WPF的东西。看到这个链接AvalonEdit。这是一个文本编辑器控件。

您可能会尝试使用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> 

它看起来像 Screenshot

+0

哦......是possiblly马特Burland的答案重复....我没看过所有的答案。 – Gqqnbig 2012-03-20 13:42:36