Skip to content

Commit a33d8c0

Browse files
authored
Update FindOnPage.md
1 parent a74ffa9 commit a33d8c0

1 file changed

Lines changed: 66 additions & 33 deletions

File tree

FindOnPage.md

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,81 @@ bool AppWindow::ExecuteFindWithCustomUI(const std::wstring& searchTerm)
143143
//! [ExecuteFindWithCustomUI]
144144
```
145145
```csharp
146-
//! [ConfigureAndExecuteFind]
147-
async void ConfigureAndExecuteFindAsync(string searchTerm){
148-
try
146+
//! [ConfigureAndExecuteFindWithDefaultUI]
147+
async Task ConfigureAndExecuteFindWithDefaultUIAsync(string searchTerm)
148+
{
149+
try
150+
{
151+
// Check if the webView is already initialized and is an instance of CoreWebView2.
152+
if (webView.CoreWebView2 == null)
149153
{
150-
// Assuming 'webView' is already initialized and is an instance of CoreWebView2
151-
152-
// Initialize find configuration/settings
153-
CoreWebView2FindConfinguration findConfiguration = new CoreWebView2FindConfiguration
154-
{
155-
FindTerm = searchTerm,
156-
IsCaseSensitive = false,
157-
ShouldMatchWord = false,
158-
FindDirection = CoreWebView2FindDirection.Forward
159-
};
160-
161-
CoreWebView2Find find = new CoreWebView2Find(findConfiguration);
154+
throw new InvalidOperationException("WebView2 is not initialized.");
155+
}
162156
163-
// Assuming you want to use the default UI, adjust as necessary
164-
find.UseCustomUI = false;
165-
find.ShouldHighlightAllMatches = true;
157+
// Initialize the find configuration with specified settings.
158+
var findConfiguration = new CoreWebView2FindConfiguration
159+
{
160+
FindTerm = searchTerm,
161+
IsCaseSensitive = false,
162+
ShouldMatchWord = false,
163+
FindDirection = CoreWebView2FindDirection.Forward
164+
};
166165
167-
// Start the find operation
168-
await find.StartFindAsync(findConfiguration);
166+
// Use the default UI provided by WebView2 for the find operation.
167+
webView.CoreWebView2.FindController.UseCustomUI = false;
168+
webView.CoreWebView2.FindController.ShouldHighlightAllMatches = true;
169169
170-
// Perform FindNext operations
171-
await find.FindNextAsync();
172-
await find.FindNextAsync();
173-
await find.FindPreviousAsync();
170+
// Start the find operation with the specified configuration.
171+
await webView.CoreWebView2.FindController.StartFindAsync(findConfiguration);
174172
175-
// Stop the active find session
176-
await find.StopFindAsync();
173+
// End user interaction is handled via UI.
174+
}
175+
catch (Exception ex)
176+
{
177+
// Handle any errors that may occur during the find operation.
178+
Console.WriteLine($"An error occurred: {ex.Message}");
179+
}
180+
}
181+
//! [ConfigureAndExecuteFindWithDefaultUI]
182+
```
177183

178-
return true;
179-
}
180-
catch (Exception ex)
184+
```csharp
185+
//! [ConfigureAndExecuteFindWithCustomUI]
186+
async Task ConfigureAndExecuteFindWithCustomUIAsync(string searchTerm)
187+
{
188+
try
189+
{
190+
// Check if the webView is already initialized and is an instance of CoreWebView2.
191+
if (webView.CoreWebView2 == null)
181192
{
182-
// Handle errors
183-
Console.WriteLine($"An error occurred: {ex.Message}");
184-
return false;
193+
throw new InvalidOperationException("WebView2 is not initialized.");
185194
}
195+
196+
// Initialize the find configuration with specified settings.
197+
var findConfiguration = new CoreWebView2FindConfiguration
198+
{
199+
FindTerm = searchTerm,
200+
IsCaseSensitive = false,
201+
ShouldMatchWord = false,
202+
FindDirection = CoreWebView2FindDirection.Forward
203+
};
204+
205+
// Specify that a custom UI will be used for the find operation.
206+
webView.CoreWebView2.FindController.UseCustomUI = true;
207+
webView.CoreWebView2.FindController.ShouldHighlightAllMatches = true;
208+
209+
// Start the find operation with the specified configuration.
210+
await webView.CoreWebView2.FindController.StartFindAsync(findConfiguration);
211+
// It's expected that the custom UI for navigating between matches (next, previous)
212+
// and stopping the find operation will be managed by the developer's custom code.
213+
}
214+
catch (Exception ex)
215+
{
216+
// Handle any errors that may occur during the find operation.
217+
Console.WriteLine($"An error occurred: {ex.Message}");
218+
}
186219
}
187-
//! [ConfigureAndExecuteFind]
220+
//! [ConfigureAndExecuteFindWithCustomUI]
188221
```
189222

190223
### Retrieve the Number of Matches

0 commit comments

Comments
 (0)