Search code examples
bindingflowdocument

Binding blocks of a Section to another Section


I have a FlowDocument with several Paragraps and Tables, this FlowDocument should repeat itself presenting the exact copy after the middle of the page. I'm using 2 Sections to achieve that.

To make thing easy, I'm trying to bind a section to another:

<Section x:Name="MainSection" Padding="10">
    <!-- Lots of things -->
</Section>

<Section Padding="10" Blocks="{Binding ElementName=MainSection, Path=Blocks}"/>

But unfortunately, Blocks does not have an accessible setter. How could I replicate the contents without having to duplicate my XAML?

PS: I'm not using C# code to create the page visual, only to fill in the paragraphs and tables.


Solution

  • Create a custom control that inherits from Section and create a bindable property and instead of binding it to Blocks you bind it to the new property. Inside the custom control, handle the property changed for that new property and add the value to the actual Blocks property.