I am trying to implement a search/highlight function in my series of CefSharp
samples and I am having trouble figuring it out. I guess, partly because some
parameters are ignored and partly because I do not know how to use it properly.
I am using a text changed event ...
<TextBox Text="{Binding Find.Text2Find,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
behav:TextChangedBehavior.TextChangedCommand="{Binding Find.FindTextChangedCommand}"
MinWidth="200"
Grid.Column="2" />...to fire a method in a viewmodel:
https://github.com/Dirkster99/KB/blob/master/00_HelloWorld/KnowledgeBase%20-%20Sample%207%20LocalZipSchemeHandler/KnowledgeBase/ViewModels/FindTextViewModel.cs
private void ExtendFindString(string findText)
{
// Don't search the same string twice
if (string.Compare(this.Text2Find, findText, this.mMatchCase) == 0)
return;
this.Text2Find = findText;
// stop searching if we have no text to find
if (string.IsNullOrEmpty(this.mText2Find) == true)
{
this.StopSearch();
return;
}
if (this.mBrowser != null)
{
// Console.WriteLine("Finding Text: '{0}'", Text2Find);
this.mBrowser.WebBrowser.StopFinding(false);
this.mBrowser.WebBrowser.Find(0, this.mText2Find, false, this.mMatchCase, true);
}
}
I find that this code works but it behaves odd. This can be verified when you type the word 'CefBrowser' in the find textbox.
The application starts to highlight the last occurrence of the string and scrolls backward towards the top as I type each letter(?).
Changing the parameters in the Find(...) method does not seem to change the over all behavior.
What I'd like to have is a way of highlighting the first occurrence and keeping the view at its present location if the next typed letters
occur in the currently highlighted word (just as in Google chrome).
And I would also like to use the '<', '>' buttons to scroll through the sequence of occurrences in a document?
How do I do this? Here is a sequence of screenshots that you can get if you verify the workflow stated above: