0

After thoroughly reading the documentation on flowdocuments (in WPF) it seems as though flowdocument does not easily support databinding. PLEASE say this is not true! I have a listbox using the sample data in Expression Blend and I inserted a textblock into the flowdocument. The textblock (text property) is databinded to the string data in the listbox. After running the project I would expect that the textblock text changes as the listbox selection changes, but nothing happens. Databinding is not working. What is the easiest way to make databinding work with flowdocument?

Here is the XAML.

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
    <DataTemplate x:Key="ItemTemplate">
        <StackPanel>
            <TextBlock Text="{Binding Property1}"/>
            </StackPanel>
    </DataTemplate>
</Window.Resources>

<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
    <FlowDocumentScrollViewer Margin="120,64,256,126">
        <FlowDocument>
            <Paragraph><Run Text="Only A Test"/><InlineUIContainer>
                    <TextBlock TextWrapping="Wrap" Text="{Binding Collection[0].Property1}" Height="56" Width="112"/>
                </InlineUIContainer></Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
    <ListBox ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}" Margin="0,83.847,52,62.153" HorizontalAlignment="Right" Width="200"/>
</Grid>
</Window>
user2096837
  • 105
  • 1
  • 2
  • 8

1 Answers1

1

According to this Microsoft documentation in April 2009, this is not possible:

While there are many great features in flow documents, if your documents are generated from dynamic data, you have a bit of a problem: there is no support for data binding in flow documents. The flow document elements (Section, Table, Run, Paragraph and the like) are dependency objects, but don't define any dependency properties that would allow you to dynamically change or generate content.

Pang
  • 9,564
  • 146
  • 81
  • 122