Hello, I hope you can help me,
I have a problem with WPF DataBinding in a FlowDocument. Here's a short description what I want to do: My aim is to print or export a XPS-Document which is build from a FlowDocument. In the FlowDocument I set some XML-Bindings which should represent the content of the XMLNode. In my XMLSource i'm storing values of my mainform-controls. Some of the mainform-controls are CheckBoxes and i want to represent these CheckBoxes in a checkbox-style in the FlowDocument. So i thought i can use DataTrigger to set the content of the checkbox-spans like this:
<Style x:Key="TrueFalseCheckBox" TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Wingdings"/>
<Setter Property="FontSize" Value="10pt"/>
<Style.Triggers>
<DataTrigger Binding="{Binding XPath=child::text(), Mode=OneWay}" Value="True">
<Setter Property="TextBlock.Text" Value="ý"/>
</DataTrigger>
<DataTrigger Binding="{Binding XPath=child::text(), Mode=OneWay}" Value="False">
<Setter Property="TextBlock.Text" Value="¨"/>
</DataTrigger>
</Style.Triggers>
</Style>
the span for representing checkboxes is like this:
<Span>
<TextBlock Style="{StaticResource TrueFalseCheckBox}">
<TextBlock.DataContext>
<Binding Source="{StaticResource xmlFileRes}" XPath="/form/ControlContent" Mode="OneWay" FallbackValue="False" />
</TextBlock.DataContext>
</TextBlock>
</Span>
The problem is the synchronization of the DataContent. If i print or export my XPS-document with the methods for exporting and printing the checkbox-spans are empty. Only if i use the FlowDocumentViewer in my c#-program the characters are shown and correctly filled (true -> marked box, false->empty box). Even if i use a PDF-printer the content of the spans is shown. When i print or export the content of the Spans that are bound directly to the XMLnodes is shown in the exported XPS-file as i want. This runs since i switched the XMLDataProvider to IsAsync="false". But i found no way to force the DataTriggers to work asynchroniously or to update programmatically. Is there any way to wait with exporting until the DataTriggers have run? (Perhaps theres a Way with Mutexes, Semaphores or something) Or is there a way to update the DataTriggers manually.
It would be nice if you can give me an advice, thanks in advance.