Home Dashboard Directory Help
Search

FixedDocument and DocumentViewer classes do not expose sufficient public APIs to enable finding and selecting text by Steve678


Status: 

Resolved
 as Fixed Help for as Fixed


14
0
Sign in
to vote
Type: Suggestion
ID: 323452
Opened: 1/22/2008 7:50:35 AM
Access Restriction: Public
2
Workaround(s)
view

Description

We are creating an application which will allow users to read and display 3rd party files such as Word Documents, HTML files, PDF documents and spreadsheets.

We intend to implement this functionality by:
- converting 3rd party files to XPS documents.
- using WPF’s DocumentViewer control to display the resulting XPS document in our application.
- using a custom template to hide the DocumentViewer’s ToolBar and FindToolBar.

This works fine, however, using our application users should also be to:
- highlight text in 3rd party files and launch commands in relation to the highlighted text.
- find words and phrases in 3rd party files, with a GUI that is part of our application and not part of the DocumentViewer window.

These requirements are more challenging because:
1. TextSelection is not exposed on the DocumentViewer control. There is no programmatic way to get or select the currently selected text.
2. The DocumentViewer control does not provide a public API for its Find functionality.
3. WPF does not provide a public API for finding text inside FixedDocuments.

Are any of the issues (1 to 3) listed above likely to be addressed a future release of WPF?
Details
Sign in to post a comment.
Posted by gstercken on 12/17/2010 at 1:27 AM
Since this is marked resolved as fixed: Is this really fixed in .NET Framework 4.0? If yes, how so?

Thanks!
Posted by stevensrf on 2/17/2010 at 1:49 PM
The DocumentViewerExample.cs is not available for download.
Can you email the DocumentViewerExample.cs document.
My email is steve_44@inbox.com
Posted by Microsoft on 3/4/2009 at 3:34 PM
Hello,

Thanks for the feedback, we will consider this one for future releases.

WPF Team
Posted by mrwhippyicecream on 5/7/2008 at 9:26 AM
I need this. Also, please could Steve678 send me the code (DocumentViewerExample.cs)!. I am trying in vain here to reconstruct what he has done...

MICROSOFT: Can't we just download the attachments that people provide?
Posted by Lakeside Developer on 2/9/2008 at 10:09 PM
I've also tried to get this to work for two weeks now. If someone has figured it out, can you post the source code for us mere mortals?

Thanks

P.S. Microsoft, please fix ASAP!
Posted by ioana.iacob on 2/1/2008 at 9:30 AM
Hi, I need the text selection functionality too, but I can't find the attached example. Could you please let me know if you still have it.
Sign in to post a workaround.
Posted by Valery Possoz on 2/16/2011 at 4:23 AM
To select text I did it like this:

            this.MouseLeftButtonDown += new MouseButtonEventHandler(IXTextBlock_MouseDown);
            this.MouseLeftButtonUp += new MouseButtonEventHandler(IXTextBlock_MouseUp);
...

        void IXTextBlock_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (mouseIsDown)
            {
                mouseUpPosition = e.GetPosition(this);
                TextPointer textPointerMouseCurrent = this.ContentStart;
                textPointerMouseCurrent = this.GetPositionFromPoint(mouseUpPosition, true);
                TextRange range = new TextRange(textPointerMouseDown, textPointerMouseCurrent);
                range.ApplyPropertyValue(TextElement.BackgroundProperty, System.Windows.Media.Brushes.Yellow);
                mouseIsDown = false;
            }
            e.Handled = true;
        }

        void IXTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            mouseIsDown = true;
            mouseDownPosition = e.GetPosition(this);
            textPointerMouseDown = this.ContentStart;
            textPointerMouseDown = this.GetPositionFromPoint(mouseDownPosition, true);
            e.Handled = true;
        }
Posted by Daniel Palme on 1/14/2010 at 1:52 AM
One possibility is to use reflection:

object toolbar = documentViewer.Template.FindName("PART_FindToolBarHost", documentViewer);

PropertyInfo contentInfo = toolbar.GetType().GetProperty("Content");
object findToolbar = contentInfo.GetValue(toolbar, null);

FieldInfo findTextBoxFieldInfo = findToolbar.GetType().GetField("FindTextBox", BindingFlags.NonPublic | BindingFlags.Instance);
TextBox findTextBox = (TextBox)findTextBoxFieldInfo.GetValue(findToolbar);

findTextBox.Text = "Text";