Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<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>


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...

C++
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
Posted
Updated 3-Sep-10 4:55am
v2

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900