Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在windows 8应用程序中滚动RichTextBlock_Windows_Windows 8_Winrt Xaml - Fatal编程技术网

在windows 8应用程序中滚动RichTextBlock

在windows 8应用程序中滚动RichTextBlock,windows,windows-8,winrt-xaml,Windows,Windows 8,Winrt Xaml,我在ScrollViewer中有一个RichTextBlock。RichTextBlock的内容非常长。如何在RichTextBlock中滚动这些文本? 我想在富文本块中随着文本在文本块中的附加而实现滚动。这里的输入是通过一个文本框给出的&文本框中的文本被附加到富文本块中 > > > > > >宽度=“1200” >高度=“

我在ScrollViewer中有一个RichTextBlock。RichTextBlock的内容非常长。如何在RichTextBlock中滚动这些文本? 我想在富文本块中随着文本在文本块中的附加而实现滚动。这里的输入是通过一个文本框给出的&文本框中的文本被附加到富文本块中


>                 
>                     
>                     
>                 
>         
>宽度=“1200”
>高度=“350”
>背景=“#FFFF”>
>宽度=“1200”
>高度=“350”
>水平滚动条可见性=“已禁用”
>水平滚动模式=“已禁用”
>VerticalScrollBarVisibility=“可见”
>VerticalScrollMode=“自动”>
>Grid.Row=“0”
>宽度=“1200”
>高度=“350”
>FontSize=“40”
>前景=“黑色”
>ScrollViewer.VerticalScrollBarVisibility=“可见”>
>                             
>                                 
>                             
>                         
>                     
>                 
>         
>Grid.Row=“1”
>宽度=“1200”
>高度=“100”
>FontSize=“40”
>                          />
>宽度=“150”
>高度=“50”
>水平对齐=“左”
>垂直对齐=“底部”
>单击=“b发送\u单击”
>Content=“发送”/>
>             
>     
>     
>     
>     
>私有无效BTN发送\单击(对象发送者,路由目标e)
>                     {
>LoadData2();
>                     }
>         
>私有void LoadData2()
>                 {
>字符串输入=txtBoxChat.Text;
>字符串模式=”;
>string[]substring=Regex.Split(输入,模式);
>对于(var i=0;i                     {
>var项目=子字符串[i];
>运行run1=新运行();
>Run run2=新运行();
>run1.Text=项目;
>添加(第1行);
>         
>字符串k=“”;
>run2.Text=k;
>添加(第2行);
>         
>                     }
>运行run3=新运行();
>run3.Text=“\n”;
>添加(第3行);
>                     
>                 }

我不确定您要使用什么事件,但我会让您决定。然后执行以下操作:

public void CauseScroll()
{
    var box = new RichTextBlock();
    var scroll = Children(box).First(x => x is ScrollViewer) as ScrollViewer;
    scroll.ChangeView(null, scroll.ScrollableHeight, null);
}

public static IEnumerable<FrameworkElement> Children(FrameworkElement element)
{
    Func<DependencyObject, List<FrameworkElement>> recurseChildren = null;
    recurseChildren = (parent) =>
    {
        var list = new List<FrameworkElement>();
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
        {
            var child = VisualTreeHelper.GetChild(parent, i);
            if (child is FrameworkElement)
                list.Add(child as FrameworkElement);
            list.AddRange(recurseChildren(child));
        }
        return list;
    };
    var children = recurseChildren(element);
    return children;
}
public void CauseScroll()
{
变量框=新的RichTextBlock();
var scroll=Children(box)。首先(x=>x是ScrollViewer)作为ScrollViewer;
scroll.ChangeView(null,scroll.ScrollableHeight,null);
}
公共静态IEnumerable子元素(FrameworkElement)
{
Func recurseChildren=null;
recurseChildren=(父项)=>
{
var list=新列表();
for(int i=0;i
这将滚动到底部


祝你好运!

你能发布一些代码让我们看看要修复什么吗?亲爱的Flip Skakun我已经发布了我的Xaml代码及其相应的.cs代码。
public void CauseScroll()
{
    var box = new RichTextBlock();
    var scroll = Children(box).First(x => x is ScrollViewer) as ScrollViewer;
    scroll.ChangeView(null, scroll.ScrollableHeight, null);
}

public static IEnumerable<FrameworkElement> Children(FrameworkElement element)
{
    Func<DependencyObject, List<FrameworkElement>> recurseChildren = null;
    recurseChildren = (parent) =>
    {
        var list = new List<FrameworkElement>();
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
        {
            var child = VisualTreeHelper.GetChild(parent, i);
            if (child is FrameworkElement)
                list.Add(child as FrameworkElement);
            list.AddRange(recurseChildren(child));
        }
        return list;
    };
    var children = recurseChildren(element);
    return children;
}