views:

280

answers:

1

Hi,

I have a WPF page used as an input form which contains a number of controls on one side, and a flow document reader on the other.

I want to set the content of this document reader to a specific part of a flow document which is loaded when the form is loaded, (via a loaded event).

I have found an article explaining how to do this, using fragments, but the examples shown are only expressed in XAML.

In my case I need to update the document property of the flow document reader when the user gives focus to one the controls (I have wired up the events already) therefore I need to do this in the code behind rather than XAML.

I have tried setting the document property to:

Document#Control_Sport

where Document is the name of XAML flow document and Control_Sport is the name of the fragment I need to navigate to.

However this gives an error, it doesn't like the hash sign being there.

I tried looking on MSDN but its XAML only. Is there a way I can do this through code?

Any help would be appreciated.

Felix,

Link to MSDN article: http://msdn.microsoft.com/en-us/library/ms750478.aspx#FragmentNavigation

A: 

You can navigate to any Block within a FlowDocument by calling Block.BringIntoView.

Matt Olenik
How exactly do I do this? Could you give an example, I found block as a property of the flowreader, flowreader.document and of the flowdocument used in the flowreader.thanks, felix
Felix Fennell
The elements you add to FlowDocument are of type Block. Things like Paragraphs, Sections etc. You can call BringIntoView on any block element to make it show in a FlowDocumentReader, FlowDocumentPageViewer, etc.
Matt Olenik
Right the paragraphs in my flow document are all named as follows; <Paragraph Name="Control_Sport"> <Run FontWeight="Bold" FontSize="18">Fixture: Sport</Run> <LineBreak /><LineBreak /><Run FontStyle="Italic">Examples: Curling, Talking</Run> </Paragraph>How do I then bring this section in view? Like this, FlowScrollReader.document = Document.BringIntoView.Control_Sport"Cause that doesn't work! Sorry to keep asking, I'm new to WPF and the examples microsoft give are either in XAML or completely useless.thanks,
Felix Fennell
If you give the element a name: <Run FontWeight="Bolt" FontSize="18" x:Name="sport"> then it will generate a member of that name in the code which you can use. So in this case, sport.BringIntoView()
Matt Olenik