Feature/blazorwebview wpf composition control opt in#34869
Feature/blazorwebview wpf composition control opt in#34869mobiletonster wants to merge 5 commits intodotnet:net11.0from
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34869Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34869" |
|
Hey there @@mobiletonster! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull request overview
This PR adds a WPF-specific toggle to allow opting out of WebView2CompositionControl for BlazorWebView, enabling better performance in scenarios that don’t need XAML-over-WebView layering, while preserving the current default behavior.
Changes:
- Added
UseCompositionControl(defaulttrue) to select betweenWebView2CompositionControland standardWebView2. - Updated the exposed
WebViewsurface (and related initialization plumbing) to use a common WPFIWebView2type. - Updated WPF PublicAPI tracking with new entries and
*REMOVED*markers for the prior return types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/BlazorWebView/src/Wpf/BlazorWebView.cs | Adds UseCompositionControl DP, selects the appropriate WPF WebView2 control via template creation, and updates WebView to return IWebView2. |
| src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs | Switches the WPF WebView2 alias to IWebView2 to support either underlying control. |
| src/BlazorWebView/src/SharedSource/BlazorWebViewInitializedEventArgs.cs | Updates the WPF WebView event arg type alias to IWebView2. |
| src/BlazorWebView/src/Wpf/PublicAPI.Unshipped.txt | Records new API surface and removals for the changed WebView-returning members. |
Code Review — PR #34869Multi-model review (Claude Opus, GPT-5.4, Claude Sonnet 4.5) Independent AssessmentWhat this changes: Adds a Inferred motivation: Reconciliation with PR NarrativeAuthor claims: Feature enhancement, not a bug fix. Breaking change to Agreement: The code matches the description accurately. The approach is sound — using Findings
|
kubaflo
left a comment
There was a problem hiding this comment.
Could you please review the comment?
|
So, I'm a bit confused about all of this. Initially, I put a PR up against master and the code bot said NO...put the PR up against the .NET 10.0 branch, so I did...now the bot says NO...don't put it there. I feel like the bot needs to get the story straight...lol.
Where should this PR point to? I can put it wherever makes sense.
From: Jakub Florkowski ***@***.***>
Sent: Sunday, April 26, 2026 8:08 AM
To: dotnet/maui ***@***.***>
Cc: Tony Spencer ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/maui] Feature/blazorwebview wpf composition control opt in (PR #34869)
@kubaflo requested changes on this pull request.
Could you please review the comment?
-
Reply to this email directly, view it on GitHub<#34869 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA3SFVO5SGWUD27UZGJXUUD4XYJ3LAVCNFSM6AAAAACXQDD4VCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DCNZXGAYTCNJSHE>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
|
@mobiletonster no worries, it might be a bit confusing at first :) So the main branch is the latest maui release (currently net10), net10 branch is an old branch we had for net10 pre-releases. MauiBot asked you to target this pr to net11 branch. I've just done it; |
|
@mobiletonster I've also resolved conflicts :) |
Code Review — PR #34869 (Re-review post-retarget)Previous Finding Status
Merge Conflict ResolutionConflicts resolved by accepting CI StatusCI just started after the merge push. Verdict: LGTMConfidence: high |
Allows opting out of the WebView2CompositionControl (introduced in net10.0 to fix WPF airspace issues) in favor of the standard WebView2 control when airspace layering is not required and lower rendering overhead is preferred. - Add UseCompositionControl dependency property (default: true) to BlazorWebView, preserving existing behavior by default - Type _webview and the WebView property as IWebView2, the interface implemented by both WebView2 and WebView2CompositionControl - CreateWebViewTemplate() selects the correct control type at init time; the property-changed callback swaps the template if set before the control is added to the visual tree - Throw InvalidOperationException if UseCompositionControl is changed after the underlying WebView2 has already been created - Update WebView2WebViewManager and BlazorWebViewInitializedEventArgs shared source to use IWebView2 for the WPF type alias - Update PublicAPI.Shipped.txt to reflect the IWebView2 return types and new UseCompositionControl public API
…Unshipped.txt I misunderstood how this was used. This should correct it.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Enhanced error reporting when WebView2 template child is missing or of the wrong type. Updated public API to return IWebView2 instead of WebView2CompositionControl for greater abstraction.
c612109 to
543def2
Compare
|
@jfversluis the pr looks good! The only question is if we want it in net 11 |
|
Thanks! I appreciate your help. Do we want it in net11? I mean, we do…or sooner. We have just finished a big research project to determine our future direction for our product (currently a large WPF project) and have decided to move forward with razor components in BlazorWebView starting in WPF but then leveraging .Net Maui for a migration into a mobile version. We love having the composition control especially as we begin the migration journey and are willing to accept the performance hit while we migrate, but eventually want to switch sections to the more performant WebView2 (sans composition control) as soon as we can.
Thanks for considering this PR.
Tony Spencer
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Jakub Florkowski ***@***.***>
Sent: Monday, April 27, 2026 12:31:53 PM
To: dotnet/maui ***@***.***>
Cc: Tony Spencer ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/maui] Feature/blazorwebview wpf composition control opt in (PR #34869)
[https://avatars.githubusercontent.com/u/42434498?s=20&v=4]kubaflo left a comment (dotnet/maui#34869)<#34869 (comment)>
@jfversluis<https://github.com/jfversluis> the pr looks good! The only question is if we want it in net 11
—
Reply to this email directly, view it on GitHub<#34869 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA3SFVOCNJHMPZI54PKVWE34X6RRTAVCNFSM6AAAAACXQDD4VCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DGMRZGUYDIOBWHE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
There was a problem hiding this comment.
The issue with IWebView is that it is a very weird type - not a view type - so all existing code will have to cast to one or the other.
Not helpful, I know, but maybe we need to rather have 2 handlers and when a flag/switch is set at compile time the app can swap a handler. Like we do with the collection views on ios.
But maybe this is fine if usage is lower?
|
I'd say it the usage is not that popular so we might keep the pr as it is |
Description of Change
This change introduces an opt‑out mechanism for using
WebView2CompositionControlin WPF BlazorWebView scenarios.While
WebView2CompositionControlresolves the WPF airspace issue, it introduces measurable rendering overhead thatnegatively impacts Razor component performance.
For apps that do not require XAML‑over‑WebView layering, developers can now disable the composition control and fall
back to the standard
WebView2, resulting in significantly improved performance on WPF.This feature also addresses feedback from the original
WebView2CompositionControlintroduction(PR #31777: #31777)
and community requests asking for an opt‑in/opt‑out toggle
(Issue #28063: #28063).
Issues Fixed / Related
WebView2CompositionControlrequest and discussion:Allow use of new WebView2CompositionControl for WPF BlazorWebView #28063
Use the WebView2CompositionControl in Blazor WPF #31777
This PR enables opting out of
WebView2CompositionControl(added in .NET 10.0 to address WPF airspace issues) infavor of the standard
WebView2when airspace layering is unnecessary and lower rendering overhead is preferred.Summary of Changes
UseCompositionControldependency property (default:true) onBlazorWebView, preserving existingbehavior.
_webviewand theWebViewproperty to useIWebView2, implemented by bothWebView2andWebView2CompositionControl.CreateWebViewTemplate()now selects the correct control type at initialization; the property‑changed callbackupdates the template if changed before the control is added to the visual tree.
InvalidOperationExceptionifUseCompositionControlis modified after the underlying WebView has beencreated.
WebView2WebViewManagerandBlazorWebViewInitializedEventArgsshared source to use the WPFIWebView2alias.
*REMOVED*entries for the oldWebView2CompositionControlreturn typesand the new
IWebView2andUseCompositionControlpublic API surface.PR Review Feedback Addressed
*REMOVED*entries inPublicAPI.Unshipped.txt— Added*REMOVED*entries for bothBlazorWebViewInitializedEventArgs.WebViewandBlazorWebView.WebViewto satisfy the API analyzer.OnApplyTemplate()— Replaced the direct(IWebView2)cast with anis notpattern match thatthrows a descriptive
InvalidOperationExceptionif the template child is missing or the wrong type.DeviceTestsproject targetsthe MAUI handler layer and is not appropriate for standalone WPF control tests. A dedicated WPF test project would be
a disproportionate investment for this change and has been deferred.
WebViewreturn type / source compatibility — The change fromWebView2CompositionControl!toIWebView2!isintentional and documented. The proposed alternative (keeping
WebViewasWebView2CompositionControl?and adding aWebViewBaseproperty) would itself be a breaking change (nullable return) and would produce a confusing two-propertyAPI. Callers relying on
WebView2CompositionControl-specific members can cast explicitly.Notes
This is not a bug fix; it is a feature/performance enhancement.