WPF WebView Source property reflects current document location #2538
Conversation
When navigating via means other than the `Source` property (e.g. `Navigate` method), or when the document is redirected with a 301/302 response, the `Source` property is not properly updated. The only reliable means of getting the document was to call `InvokeScriptAsync("eval", "window.location.href")`.
The following changes address the issue:
- Navigation of the underlying control is no longer controlled by updating the dependency property. This permits the value of the property to be updated when a change is detected.
- The SourceProperty dependency property has its new value set from the arguments provided in the `NavigationCompleted` event.
- Calling `void Navigate(Uri)` calls the underlying Navigate method instead of relying on the depenency property update to navigate the control.
- Setting the value of `Source` now calls `void Navigate(Uri)` if the control is initialized; otherwise, it only sets the `SourceProperty` dependency value. Navigation to the stored value will occur when the control is ready to navigate after asynchronous initialization.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Issue: #2537
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When navigating via means other than the
Sourceproperty (e.g.Navigatemethod), or when the document is redirected with a 301/302 response, theSourceproperty is not properly updated. The only reliable means of getting the document was to callInvokeScriptAsync("eval", "window.location.href").What is the new behavior?
The following changes address the issue:
NavigationCompletedevent.void Navigate(Uri)calls the underlying Navigate method instead of relying on the depenency property update to navigate the control.Sourcenow callsvoid Navigate(Uri)if the control is initialized; otherwise, it only sets theSourcePropertydependency value. Navigation to the stored value will occur when the control is ready to navigate after asynchronous initialization.PR Checklist
Please check if your PR fulfills the following requirements:
Other information
Fixes #2537