Lingua

CoreWebView2Find Class

Definition

Provides methods and properties for finding and navigating through text in the web view. This class allows for finding text, navigation between matches, and customization of the find UI.

public class CoreWebView2Find
type CoreWebView2Find = class
Public Class CoreWebView2Find
Inheritance
CoreWebView2Find

Properties

Name Description
ActiveMatchIndex

Retrieves the index of the currently active match in the find session. Returns the index of the currently active match, or -1 if there is no active match. The index starts at 1 for the first match.

MatchCount

Gets the total count of matches found in the current document based on the last find session's criteria. Returns the total count of matches.

Methods

Name Description
FindNext()

Navigates to the next match in the document. If there are no more matches to find, FindNext will wrap around to the first match's index.

If called when there is no find session active, FindNext throws an InvalidOperationException.

FindPrevious()

Navigates to the previous match in the document. If there are no more matches to find, FindPrevious will wrap around to the last match's index.

If called when there is no find session active, FindPrevious throws an InvalidOperationException.

StartAsync(CoreWebView2FindOptions)

Initiates a find using the specified find options asynchronously. Displays the Find bar and starts the find session. If a find session was already ongoing, it will be stopped and replaced with this new instance. If FindTerm is an empty string, the Find bar is displayed but no finding occurs. Changing the CoreWebView2FindOptions object after initiation won't affect the ongoing find session. To change the ongoing find session, StartAsync(CoreWebView2FindOptions) must be called again with a new or modified CoreWebView2FindOptions object. StartAsync(CoreWebView2FindOptions) supports HTML and TXT document queries. In general, this API is designed for text-based find sessions. If you start a find session programmatically on another file format that doesn't have text fields, the find session will try to execute but will fail to find any matches. (It will silently fail) Note: The asynchronous action completes when the UI has been displayed with the find term in the UI bar, and the matches have populated on the counter on the find bar. There may be a slight latency between the UI display and the matches populating in the counter. The MatchCountChanged and ActiveMatchIndexChanged events are only raised after StartAsync(CoreWebView2FindOptions) has completed; otherwise, they will have their default values (-1 for active match index and 0 for match count). To start a new find session (beginning the search from the first match), call Stop() before invoking StartAsync(CoreWebView2FindOptions). If StartAsync(CoreWebView2FindOptions) is called consecutively with the same options and without calling Stop(), the find session will continue from the current position in the existing session. Calling StartAsync(CoreWebView2FindOptions) without altering its parameters will behave either as FindNext() or FindPrevious(), depending on the most recent search action performed. StartAsync(CoreWebView2FindOptions) will default to forward if neither have been called. However, calling StartAsync(CoreWebView2FindOptions) again during an ongoing find session does not resume from the point of the current active match. For example, given the text "1 1 A 1 1" and initiating a find session for "A", then starting another find session for "1", it will start searching from the beginning of the document, regardless of the previous active match. This behavior indicates that changing the find query initiates a completely new find session, rather than continuing from the previous match index.

Stop()

Stops the current 'Find' session and hides the Find bar. If called with no Find session active, it will silently do nothing.

Events

Name Description
ActiveMatchIndexChanged

Raised when the index of the currently active match changes. This can happen when the user navigates to a different match or when the active match is changed programmatically.

MatchCountChanged

Raised when the total count of matches in the document changes due to a new find session or changes in the document.

Applies to