@@ -327,16 +327,18 @@ within a WebView2 control using the `GetActiveMatchIndex` method.
327
327
public async Task<int> GetActiveMatchIndexAsync()
328
328
{
329
329
var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
330
- var activeMatchIndex = await webViewFind.GetActiveMatchIndexAsync ();
330
+ var activeMatchIndex = webViewFind.ActiveMatchIndex ();
331
331
MessageBox.Show($"Active Match Index: {activeMatchIndex}", "Find Operation", MessageBoxButton.OK);
332
332
return activeMatchIndex;
333
333
}
334
334
335
335
void ActiveMatchIndexChangedSample()
336
336
{
337
- _webview.matchCount Changed += (object sender, CoreWebView2ActiveMatchIndexChangedEventArgs args) =>
337
+ webView.CoreWebView2.FindController.ActiveMatchIndexChanged += (object sender, EventArgs args) =>
338
338
{
339
- // Update Custom UI
339
+ // Access the active match index synchronously in the event handler.
340
+ int activeMatchIndex = webView.CoreWebView2.FindController.ActiveMatchIndex;
341
+ // Update Custom UI based on the new active match index.
340
342
};
341
343
}
342
344
//! [GetActiveMatchIndex]
@@ -504,21 +506,22 @@ namespace Microsoft.Web.WebView2.Core
504
506
Backward ,
505
507
};
506
508
507
- runtime CoreWebView2Find
509
+ runtime CoreWebView2Find
510
+ {
511
+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Find" )]
508
512
{
509
- [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Find" )]
510
- {
511
- void StartFindAsync(CoreWebView2FindConfiguration configuration);
512
- void FindNextAsync();
513
- void FindPreviousAsync();
514
- void StopFindAsync();
515
- bool ShouldHighlightAllMatches { get; set; }
516
- bool ShouldHighlightActiveMatch { get ; set ; }
517
- bool UseCustomUI { get ; set ; }
518
- int GetActiveMatchIndexAsync ();
519
- int GetMatchesCountAsync ();
520
- }
513
+ void StartFind(CoreWebView2FindConfiguration configuration);
514
+ void FindNext();
515
+ void FindPrevious();
516
+ void StopFind();
517
+ bool ShouldHighlightAllMatches { get; set; }
518
+ bool ShouldHighlightActiveMatch { get ; set ; }
519
+ bool UseCustomUI { get ; set ; }
520
+ int ActiveMatchIndex { get ; }; // Synchronously gets the active match index.
521
+ int MatchesCount { get ; }; // Synchronously gets the matches count.
521
522
}
523
+ }
524
+
522
525
523
526
runtimeclass CoreWebView2FindConfiguration {
524
527
[interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2StagingFindConfiguration" )]
0 commit comments