Richbox的垂直滚动条 [英] Richbox's Vertical Scrollbar

查看:114
本文介绍了Richbox的垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

当你在richbox中有很多行(richbox的高度非常短)并且你应用了很多新行。你想让Richbox的垂直滚动条总是在每次应用新行时都是底部。



问题:

问题是该怎么办?





Goal:
When you have alot of row inside of a richbox (richbox's height is very short) and you apply a lot of new rows. you want to make the richbox's vertical scrollbar always to be the bottom every time a new row is applied.

Problem:
The question is how to do it?


private void btn_test_Click(object sender, RoutedEventArgs e)
  {
   Table table = newRtb.FindName("MyTable") as Table;
   foreach (TableRow row in table.RowGroups[0].Rows)
   {
    if (row.Background == Brushes.SpringGreen)
    {
     //get value of third cell:
     BlockUIContainer container = row.Cells[2].Blocks.ElementAt(0) as BlockUIContainer;
     TextBlock textBlock = container.Child as TextBlock;
     MessageBox.Show(textBlock.Text);
    }
   }
  }

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  {
   var tab = new Table();
   tab.Name = "MyTable";
   newRtb.RegisterName("MyTable", tab);


   var gridLenghtConvertor = new GridLengthConverter();

   tab.Columns.Add(new TableColumn() { Name = "Column1", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });
   tab.Columns.Add(new TableColumn() { Name = "Column2", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });
   tab.Columns.Add(new TableColumn() { Name = "Column3", Width = new GridLength(0) });

   tab.RowGroups.Add(new TableRowGroup());

   for (int i = 0; i < 10; i++)
   {
    TableRow tr = new TableRow();
    tr.MouseLeftButtonDown += tr_MouseLeftButtonDown;
    tab.RowGroups[0].Rows.Add(tr);
    var tabRow = tab.RowGroups[0].Rows[i];

    tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column1"))) { TextAlignment = TextAlignment.Center });
    tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column2"))));

    BlockUIContainer container = new BlockUIContainer();
    container.Child = new TextBlock(){ Text = "Test"};
    tabRow.Cells.Add(new TableCell(container));
   }


   newRtb.Document.Blocks.Add(tab);

  }

推荐答案

你需要一个垂直滚动条而不是水平滚动条。

使用 rtb.ScrollToEnd()方法滚动到richtextbox的底部。如果没有任何反应,请设置 ScrollViewer.VerticalScrollBarVisibility =Auto并解决问题。
you need to have a vertical scrollbar not a horizontal one.
Use rtb.ScrollToEnd() method which scrolls to the bottom of the richtextbox. if nothing happens, set ScrollViewer.VerticalScrollBarVisibility="Auto" and it soves the issue.


这篇关于Richbox的垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆