Skip to content

Commit af525b6

Browse files
authored
Update FindOnPage.md
1 parent b1a63fb commit af525b6

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

FindOnPage.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This method allows specifying the find term and configuring other find parameter
1717
#### Create/Specify a Find Configuration
1818
```cpp
1919

20-
//! [ConfigureAndExecuteFind]
20+
//! [ConfigureAndExecuteFind]
2121
bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
2222
{
2323
// Query for the ICoreWebView2Environment5 interface.
@@ -71,6 +71,52 @@ bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
7171
return true;
7272
}
7373
//! [ConfigureAndExecuteFind]
74+
```
75+
```csharp
76+
//! [ConfigureAndExecuteFind]
77+
public async Task<bool> ConfigureAndExecuteFindAsync(string searchTerm)
78+
{
79+
try
80+
{
81+
// Assuming 'webView' is already initialized and is an instance of CoreWebView2
82+
83+
// Initialize find configuration/settings
84+
var findConfiguration = new CoreWebView2FindConfiguration
85+
{
86+
FindTerm = searchTerm,
87+
IsCaseSensitive = false,
88+
ShouldMatchWord = false,
89+
FindDirection = CoreWebView2FindDirection.Forward
90+
};
91+
92+
// Use the FindController to start the find operation
93+
var findController = webView.FindController;
94+
95+
// Assuming you want to use the default UI, adjust as necessary
96+
findController.UseCustomUI = false;
97+
findController.ShouldHighlightAllMatches = true;
98+
99+
// Start the find operation
100+
await findController.StartFindAsync(findConfiguration);
101+
102+
// Perform FindNext operations
103+
await findController.FindNextAsync();
104+
await findController.FindNextAsync();
105+
await findController.FindPreviousAsync();
106+
findController.StopFind();
107+
108+
return true;
109+
}
110+
catch (Exception ex)
111+
{
112+
// Handle errors
113+
Console.WriteLine($"An error occurred: {ex.Message}");
114+
return false;
115+
}
116+
}
117+
}
118+
//! [ConfigureAndExecuteFind]
119+
```
74120

75121
//! [StopFind]
76122
bool AppWindow::StopFind()

0 commit comments

Comments
 (0)