2012-03-20 65 views
0

我想要一個帶行號的文本框。所以我決定使用一個小文本框作爲左側的行號,右側的另一個大的文本框作爲文本。 現在我的問題是,我把這兩個文本框放入一個Dockpanel中,我需要一個高度差,因爲行號的文本框不應該有滾動條。所以我需要縮短左邊的TextBox。我的計劃是在左邊的TextBox下面放置一個空的StackPanel。而且我遇到了麻煩,因爲DockPanel沒有按我的意願對我的控件進行排序。我得到它的唯一方法是使用固定寬度,但我不想要!WPF DockPanel - 訂單控件

image

或者我應該去一個完全不同的方式?

回答

0

如果您不想在控件上使用滾動條,只需將VerticalScrollBarVisibility設置爲禁用。

但我不確定那正是您需要的。如果你這樣做,那麼顯然你的行號不會隨着你的文本框滾動。最好的辦法可能是在DockPanel中放置兩個文本框(但如果行號不應該是可編輯的,則可能需要使用標籤),並將停靠面板包裹在滾動查看器中。

1

我不知道爲什麼你必須建立這個控件,但你可以找到類似WPF的東西。看到這個鏈接AvalonEdit。這是一個文本編輯器控件。

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> 

它看起來像 Screenshot

+0

哦......是possiblly馬特Burland的答案重複....我沒看過所有的答案。 – Gqqnbig 2012-03-20 13:42:36