I have a WPF usercontrol that I want to load with dynamic content in code using a FlowDocument: textblocks, bulleted lists, etc. Content is loaded as expected. And the box sizes looks fine in designer, but in runtime the FlowDocument insists on clipping the result and only show part of the width.
My assumption was that the Viewbox would fill the grid cell and the inner FlowDocument to fill up all available space.
I tried to set the PageWidth/PageHeigth of the FlowDocument in code but with no result.
The problem lies in the fact that Viewbox scaling is based on the design time size of the child object. Even if the actual size of the internal child objects are bigger, they will still report their design time size also to the ActualWidth and ActualHeight properties. This is kind of confusing.
The workaround is to create the whole content including the FlowDocumentScrollViewer and its FlowDocument in runtime. They will then be based on the current available space and will fill the content as expected.
In my case the purpose was to make a simple markdown parser that will generate dynamic layout. This is now implemented and working fine :)
Asked in February 2016Viewed 1,644 timesVoted 7Answered 1 times