如何使TextBox在WPF中滚动

如何使TextBox在WPF中滚动

问题描述:

我在wpf应用程序中使用一个头控件,我使用了网格,并且在该网格中我将List框一些按钮 和文本框。我想让该文本框可以滚动。能否请您给我的解决方案如何使TextBox在WPF中滚动

对于一个文本框设置了以下属性:

<TextBox AcceptsReturn="True" 
VerticalScrollBarVisibility="Auto"/> 

你说:

I have tried this but it is not working <Label Content="Log Details" Grid.Row="4" ></Label> <Border Margin="7,7,7,3" Grid.Row="5"> <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="5" > <StackPanel > <TextBox Margin="5" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" IsReadOnly="True" x:Name="LogDetails"></TextBox> </StackPanel> </ScrollViewer> </Border> I am putting this in headercontrol. – jolly 

其实,你不”因为TextBox已经在其Template中关联了一个ScrollViewer,所以需要将一个TextBox放入一个ScrollViewer中。 但是,如果你有在你需要做同样的你的具体要求,你可以尝试这样的事:

<Label Content="Log Details" Grid.Row="4" ></Label> 
    <Border Margin="7,7,7,3" Grid.Row="5"> 
     <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="5" > 
      <StackPanel> 
       <TextBox Margin="5" TextWrapping="Wrap" AcceptsReturn="True" IsReadOnly="True" x:Name="LogDetails"></TextBox> 
      </StackPanel> 
     </ScrollViewer> 
    </Border> 

尝试:

<ScrollViewer> 
    <Textbox/> 
</ScrollViewer> 
+0

我都试过,但它不工作 ScrollViewer> 我把它放在headercontrol中。 – jolly 2009-11-17 06:36:49