Tuesday, August 21, 2007

WPF FlowDocuments

While messing around with FlowDocuments in a WPF app, I was trying to find a way to remove the nice reader controls. I think they are great, those controls come for free and allow you to zoom, change the page layout as well as search. I was after the ability to flow text around an image, but didn't want all the extra fruit.





Quite by accident I found that placing the FlowDocumentPageViewer inside a StackPanel removed the FlowDocument controls. I've not looked up any documentation to see if that is by design, but it works.

<Border CornerRadius="5,5,0,0" BorderThickness="2" BorderBrush="Blue" Visibility="Visible" Panel.ZIndex="0">







<StackPanel>







<FlowDocumentPageViewer>







image
<FlowDocument>







<Paragraph>







This is a richTextBox. I can







<Bold>Bold</Bold> ,







<Italic>Italicize</Italic> text







</Paragraph>







<Paragraph FontSize="10">







<Figure HorizontalAnchor="ContentLeft" VerticalAnchor="ContentTop" Width="100">







<BlockUIContainer Padding="0">







<Image Height="100" Width="100" Source="Bear3.jpg" />







</BlockUIContainer>







<Paragraph Foreground="Blue" FontFamily="Consolas">







The Bear</Paragraph>







</Figure>







The quick brown fox jumps over the lazy dog. This FlowDocument with sample







content, and provides controls to toggle the IsHyphenationEnabled and IsOptimalParagraphEnabled







properties and view the resulting layout changes in real time. The sample also includes controls







for toggling the IsColumnWidthFlexible property, and adjusting the ColumnWidth and ColumnGap properties.







This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow







application development best practices. For comprehensive coverage of Windows Presentation







Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:







</Paragraph>







</FlowDocument>







</FlowDocumentPageViewer>







</StackPanel>







</
Border>




If you actually want the controls remove the StackPanel (you can use a Grid instead) and this is how it would look.








1 comment:

bkwdesign said...

I know the FlowDocumentReader control supports these attributes in the main tag:

IsFindEnabled="True|False" IsPageViewEnabled="True|False" IsScrollViewEnabled="True|False" IsTwoPageViewEnabled="True|False"