@@ -74,14 +74,13 @@ bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
7474```
7575```csharp
7676//! [ConfigureAndExecuteFind]
77- public async Task<bool> ConfigureAndExecuteFindAsync(string searchTerm)
78- {
77+ async void ConfigureAndExecuteFindAsync(string searchTerm){
7978 try
8079 {
8180 // Assuming 'webView' is already initialized and is an instance of CoreWebView2
8281
8382 // Initialize find configuration/settings
84- var findConfiguration = new CoreWebView2FindConfiguration
83+ CoreWebView2FindConfinguration findConfiguration = new CoreWebView2FindConfiguration
8584 {
8685 FindTerm = searchTerm,
8786 IsCaseSensitive = false,
@@ -90,20 +89,20 @@ public async Task<bool> ConfigureAndExecuteFindAsync(string searchTerm)
9089 };
9190
9291 // Use the FindController to start the find operation
93- var findController = webView.FindController ;
92+ CoreWebView2Find find = new CoreWebView2Find(findConfiguration) ;
9493
9594 // Assuming you want to use the default UI, adjust as necessary
96- findController .UseCustomUI = false;
97- findController .ShouldHighlightAllMatches = true;
95+ find .UseCustomUI = false;
96+ find .ShouldHighlightAllMatches = true;
9897
9998 // Start the find operation
100- await findController .StartFindAsync(findConfiguration);
99+ await find .StartFindAsync(findConfiguration);
101100
102101 // Perform FindNext operations
103- await findController .FindNextAsync();
104- await findController .FindNextAsync();
105- await findController .FindPreviousAsync();
106- findController .StopFind();
102+ await find .FindNextAsync();
103+ await find .FindNextAsync();
104+ await find .FindPreviousAsync();
105+ find .StopFind();
107106
108107 return true;
109108 }
@@ -113,22 +112,10 @@ public async Task<bool> ConfigureAndExecuteFindAsync(string searchTerm)
113112 Console.WriteLine($"An error occurred: {ex.Message}");
114113 return false;
115114 }
116- }
117115}
118116//! [ConfigureAndExecuteFind]
119117```
120118
121- //! [ StopFind]
122- bool AppWindow::StopFind()
123- {
124- auto webView2staging11 = m_webView.try_query<ICoreWebView2Staging11 >();
125- CHECK_FEATURE_RETURN(webView2staging11);
126- wil::com_ptr<ICoreWebView2StagingFind > webView2stagingfind;
127- CHECK_FAILURE(webView2staging11->get_Find(&webView2stagingfind));
128-
129- return true;
130- }
131- //! [ StopFind]
132119
133120//! [ GetMatchCount]
134121bool AppWindow::GetMatchCount()
@@ -167,140 +154,12 @@ bool AppWindow::GetActiveMatchIndex()
167154 return true;
168155}
169156//! [ GetActiveMatchIndex]
170- #endif
171-
172- bool AppWindow::ConfigureAndExecuteFind(
173- const std::wstring& searchTerm,
174- bool caseSensitive,
175- bool highlightAllMatches,
176- COREWEBVIEW2_FIND_DIRECTION direction)
177- {
178- // Query for the ICoreWebView2Environment5 interface.
179- auto webView2Environment5 = m_webViewEnvironment.try_query<ICoreWebView2Environment5>();
180- CHECK_FEATURE_RETURN(webView2Environment5);
181-
182- // Create the find configuration.
183- wil::com_ptr<ICoreWebView2FindConfiguration> findConfiguration;
184- CHECK_FAILURE(webView2Environment5->CreateFindConfiguration(&findConfiguration));
185-
186- // Apply the find operation configurations.
187- CHECK_FAILURE(findConfiguration->put_FindTerm(searchTerm.c_str()));
188- CHECK_FAILURE(findConfiguration->put_IsCaseSensitive(caseSensitive));
189- CHECK_FAILURE(findConfiguration->put_ShouldHighlightAllMatches(highlightAllMatches));
190- CHECK_FAILURE(findConfiguration->put_FindDirection(direction));
191-
192- // Proceed to execute the find operation with the configured settings.
193- return ExecuteFindOperation(findConfiguration.get());
194- }
195- ```
196-
197- ```csharp
198- public async Task<bool> ConfigureAndExecuteFindAsync(
199- string searchTerm,
200- bool caseSensitive,
201- bool highlightAllMatches,
202- CoreWebView2FindDirection direction)
203- {
204- var findConfiguration = new CoreWebView2FindConfiguration
205- {
206- FindTerm = searchTerm,
207- IsCaseSensitive = caseSensitive,
208- ShouldHighlightAllMatches = highlightAllMatches,
209- FindDirection = direction
210- };
211- return await ExecuteFindOperationAsync(findConfiguration);
212- }
213- ```
214- ### Start a Find Operation
215-
216- ``` cpp
217- // ! [StartFindOnPage]
218- bool AppWindow::ExecuteFindOperation (ICoreWebView2FindConfiguration* configuration)
219- {
220- // Query for the ICoreWebView217 interface to access the Find feature.
221- auto webView217 = m_webView.try_query<ICoreWebView217 >();
222- CHECK_FEATURE_RETURN(webView217);
223-
224- // Get the Find interface.
225- wil::com_ptr<ICoreWebView2Find > webView2find;
226- CHECK_FAILURE(webView217->get_Find(&webView2find));
227-
228- // Apply custom UI settings and highlight configurations.
229- CHECK_FAILURE(webView2find->put_UseCustomUI(false)); // Assuming you want to use the default UI, adjust as necessary.
230- CHECK_FAILURE(webView2find->put_ShouldHighlightAllMatches(true)); // This should match the passed parameter if dynamic.
231- CHECK_FAILURE(webView2find->PassHighlightSettings());
232-
233- // Start the find operation with the configured findConfiguration.
234- HRESULT result = webView2find->StartFind(
235- configuration,
236- Callback<ICoreWebView2FindOperationCompletedHandler >(
237- [ this] (HRESULT result, LONG ActiveIdx, LONG MatchesCount) -> HRESULT
238- {
239- if (SUCCEEDED(result))
240- {
241- // Handle successful find operation
242- // For example, updating UI elements to reflect the find results
243- }
244- else
245- {
246- // Handle errors appropriately
247- }
248- return S_OK;
249- }).Get());
250-
251- return SUCCEEDED(result);
252- }
253-
254- //! [ StartFindOnPage]
255157```
256-
257- ```csharp
258- //! [StartFindOnPage]
259- public async Task<bool> ExecuteFindOperationAsync(CoreWebView2FindConfiguration configuration)
260- {
261- var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
262-
263- // Assume CoreWebView2.FindController has been appropriately implemented or wrapped to expose async tasks.
264- // This example assumes such an implementation for illustration.
265- await webViewFind.StartFindAsync(configuration);
158+
159+ ### Retrieve the Number of Matches
266160
267- // Optionally, handle completion or results with events or further async operations.
268- return true;
269- }
270-
271- //! [StartFindOnPage]
272- ```
273- ### Stop an existing find operation
274161#### Description
275- To stop an ongoing find operation within a WebView2 control, developers can use the ` StopFind ` method of the ` ICoreWebView2Find ` interface.
276- ``` cpp
277- // ! [StopFind]
278- bool AppWindow::StopFind ()
279- {
280- auto webView217 = m_webView.try_query<ICoreWebView217>();
281- CHECK_FEATURE_RETURN (webView217);
282- wil::com_ptr<ICoreWebView2Find > webView2find;
283- CHECK_FAILURE(webView217->get_Find(&webView2find));
284- CHECK_FAILURE(webView2find->StopFind());
285- return true;
286- }
287- //! [ StopFind]
288- ```
289-
290- ```csharp
291- //! [StopFind]
292- public void StopFindOperation()
293- {
294- var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
295- webViewFind.StopFind();
296- }
297- //! [StopFind]
298- ```
299-
300- ### Retrieve the Number of Matches
301-
302- #### Description
303- To retrieve the total number of matches found during a find operation within a WebView2 control, developers can utilize the `GetMatchCount` method.
162+ To retrieve the total number of matches found during a find operation within a WebView2 control, developers can utilize the `GetMatchCount` method.
304163
305164
306165```cpp
@@ -411,85 +270,7 @@ private void OnActiveMatchIndexChanged(object sender, EventArgs e)
411270}
412271```
413272
414- ### Navigate to the Next Match
415-
416- #### Description
417- To navigate to the next match found during a find operation within a WebView2 control, developers can use the ` FindNext ` method.
418-
419-
420- ``` cpp
421- // ! [FindNext]
422- bool AppWindow::FindNext ()
423- {
424- auto webView217 = m_webView.try_query<ICoreWebView217>();
425- CHECK_FEATURE_RETURN (webView217);
426- wil::com_ptr<ICoreWebView2Find > webView2find;
427- CHECK_FAILURE(webView217->get_Find(&webView2find));
428-
429- CHECK_FAILURE (webView2find->FindNext());
430- CHECK_FAILURE(webView2find->remove_ActiveMatchIndexChanged(
431- m_ActiveMatchIndexChangedEventToken));
432273
433- return true;
434- }
435- // ! [FindNext]
436- ```
437-
438- ``` csharp
439- // ! [FindNext]
440- bool AppWindow :: FindNext ()
441- {
442- auto webView217 = m_webView .try_query <ICoreWebView217 >();
443- CHECK_FEATURE_RETURN (webView217 );
444- wil :: com_ptr < ICoreWebView2Find > webView2find ;
445- CHECK_FAILURE (webView217 ->get_Find (& webView2find ));
446-
447- CHECK_FAILURE (webView2find ->FindNext ());
448- CHECK_FAILURE (webView2find ->remove_ActiveMatchIndexChanged (
449- m_ActiveMatchIndexChangedEventToken ));
450-
451- return true ;
452- }
453- // ! [FindNext]
454- ```
455-
456- ### Navigate to the Previous Match
457-
458- #### Description
459- To navigate to the previous match found during a find operation within a WebView2 control, developers can use the ` FindPrevious ` method.
460-
461-
462- ``` cpp
463- // ! [FindPrevious]
464- bool AppWindow::FindPrevious ()
465- {
466- auto webView217 = m_webView.try_query<ICoreWebView217>();
467- CHECK_FEATURE_RETURN (webView217);
468- wil::com_ptr<ICoreWebView2Find > webView2find;
469- CHECK_FAILURE(webView217->get_Find(&webView2find));
470-
471- CHECK_FAILURE (webView2find->FindPrevious());
472-
473- return true;
474- }
475- // ! [FindPrevious]
476- ```
477-
478- ``` csharp
479- // ! [FindPrevious]
480- bool AppWindow :: FindPrevious ()
481- {
482- auto webView217 = m_webView .try_query <ICoreWebView217 >();
483- CHECK_FEATURE_RETURN (webView217 );
484- wil :: com_ptr < ICoreWebView2Find > webView2find ;
485- CHECK_FAILURE (webView217 ->get_Find (& webView2find ));
486-
487- CHECK_FAILURE (webView2find ->FindPrevious ());
488-
489- return true ;
490- }
491- // ! [FindPrevious]
492- ```
493274
494275## API Details
495276``` csharp
0 commit comments