添加文本后强制FlowDocumentScrollViewer刷新 [英] Forcing a FlowDocumentScrollViewer to refresh after adding text

查看:57
本文介绍了添加文本后强制FlowDocumentScrollViewer刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VC#2008创建一个包含FlowDocumentScrollViewer的对话框,其中包含有关如何在此特定对话框中执行操作的指令列表.当用户执行操作时,我将以编程方式实时添加到FlowDocumentScrollViewer.但是,直到完成特定功能后,更新才会显示出来.我正在尝试刷新控件以显示此文本,但是却无济于事.我在这里缺少一些基本知识.将此控件视为指令和进度的混合体,类似于实时跟踪记录器,它在对话框下方的逻辑校准机器时报告状态,并在运行时报告状态.

这是相关的XAML:

I am usig VC# 2008 to create a dialog containing a FlowDocumentScrollViewer which contains a list of instructions on how to do things in this particular dialog. As the user performs actions, I am ADDING to the FlowDocumentScrollViewer programatically in real time. However, the updates don''t show up until AFTER a particular function is completed. I''m trying to REFRESH the control to show this text, but am getting nowhere. There is something basic I''m missing here. Think of this control as a hybrid of instructions and progress, similar to a live trace logger that reports status as the logic underneath the dialog calibrates a machine, and reports status back as it goes along.

Here is the relevant XAML:

<Window x:Class="Hamilton.IMPACT.CalibrationWin"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"

    Title="Calibration" Height="600" Width="800"

    Closing="CalibrationWin_Closing" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"

    DataContext="{Binding RelativeSource={RelativeSource Self}}" Background="#FFFFFFFF">
    <Window.Resources>
        <ResourceDictionary Source="ResourceDictionary.xaml" />
    </Window.Resources>

    <Grid>
        <Grid Grid.Column="1" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
            <FlowDocumentScrollViewer Margin="12.0,6.0,12.0,22.0" x:Name="InstructionsTxt" FontSize="8.0"

                    BorderBrush="Black" BorderThickness="1" VerticalScrollBarVisibility="Auto">
            </FlowDocumentScrollViewer>
        </Grid>
    </Grid>
</Window>



在我的代码中,我有一对函数可为当前操作创建一个新的FlowDocument,还有第二对函数可将其添加到该FlowDocument.创建/添加有效,但是在完成操作之前,FlowDocumentScrollViewer不会显示更改.我留下了一些注释的代码,这些代码我试图用来强制进行更新,但没关系.

我想念什么???这是有问题的4个功能...



In my code, I have 1 pair of functions to create a new FlowDocument for the current action, and a 2nd pair of functions to ADD to that FlowDocument. The Creation / Addition works, but the FlowDocumentScrollViewer doesn''t show the changes until an action is finished. I''ve left some commented code that I tried to use to FORCE an update, but no deal.

What am I missing??? Here is the 4 functions in question...

private void UpdateInstructions(string instructions)
{
    if (!_mainThreadDisp.HasShutdownStarted && !_mainThreadDisp.HasShutdownFinished)
    {
        _mainThreadDisp.Invoke(System.Windows.Threading.DispatcherPriority.Normal, InstructionsUpdated, instructions);
    }
}

private void AppendInstructions(string instructions)
{
    if (!_mainThreadDisp.HasShutdownStarted && !_mainThreadDisp.HasShutdownFinished)
    {
        _mainThreadDisp.Invoke(System.Windows.Threading.DispatcherPriority.Normal, InstructionsAppended, instructions);
    }
}

private void CalibrationWin_InstructionsUpdated(string instructions)
{
    Storyboard fadeIn = (Storyboard)Resources["FadeIn"];
    Storyboard growFont = (Storyboard)Resources["GrowFont"];
    FlowDocument flowDoc = ConstructFlowDocument(instructions);
    InstructionsTxt.Document = flowDoc;
    InstructionsTxt.BeginStoryboard(fadeIn);
    flowDoc.BeginStoryboard(growFont);
    //flowDoc.BringIntoView();
    //InstructionsTxt.InvalidateVisual();
    //InstructionsTxt.BringIntoView();
    //this.InvalidateVisual();
    //this.BringIntoView();
}

private void CalibrationWin_InstructionsAppended(string instructions)
{
    Storyboard fadeIn = (Storyboard)Resources["FadeIn"];
    Storyboard growFont = (Storyboard)Resources["GrowFont"];
    FlowDocument flowDoc = AppendToFlowDocument(instructions);
    InstructionsTxt.Document = flowDoc;
    InstructionsTxt.BeginStoryboard(fadeIn);
    flowDoc.BeginStoryboard(growFont);
    //flowDoc.BringIntoView();
    //InstructionsTxt.InvalidateVisual();
    //InstructionsTxt.BringIntoView();
    //this.InvalidateVisual();
    //this.BringIntoView();
}



Michael



Michael

推荐答案

问题已解决.原来,问题与重绘无关,与原始开发人员如何处理线程问题有关.

迈克尔
Problem solved. Turns out that the problem had nothing to do with redraw, and everything to do with how the original developer dealt with threading issues.

Michael


这篇关于添加文本后强制FlowDocumentScrollViewer刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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