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>
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);
}
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);
}
Michael