-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BlazorWebView support for loading custom static assets #3191
Conversation
Each platform's BlazorWebView has a new virtual CreateFileProvider() method that you can override to return a custom IFileProvider to return static assets from wherever you want (such as embedded resources, generated, etc.). Fixes #1520
It might look like it's kind of a large PR, but it's like 80-90% sample updates, and only a small amount of product code changes. |
BTW I did consider and dismiss some other design options that I figured I'd mention here in case anyone has other thoughts:
I felt that all of these would be unnecessarily icky compared to the scope of this feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, but I suppose I think I would prefer to use a FileProvider property over a method override.
@@ -16,5 +17,11 @@ public BlazorWebView() | |||
public string? HostPage { get; set; } | |||
|
|||
public RootComponentsCollection RootComponents { get; } | |||
|
|||
/// <inheritdoc/> | |||
public virtual IFileProvider? CreateFileProvider(string contentRootDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this maybe be a property? I feel setting webview.FileProvider = Xxx
is easier than overriding. Unless I am missing some reason why this is better? Maybe even a bindable property so it can be swapped out? Unless swapping is not possible, but then I could swap out via the override logic, so that needs to be supported either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, if it is a property, then the handler can have a mapper that can update the native things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the samples with the overrides... I feel that this is not very XAML-y - an override just to return a single value...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I see your last point on the last comment is not this... Hmmm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love a property if I had a way of passing in a parameter to it... which would mean I need a new interface with such a method on it... which would mean I'd need 3 because of WPF/WinForms/MAUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the FileProvider is not as simple as I thought, so we can't quite use a property as it is made up of values and that is passed to it.
Each platform's BlazorWebView has a new virtual CreateFileProvider() method that you can override to return a custom IFileProvider to return static assets from wherever you want (such as embedded resources, generated, etc.).
Fixes #1520
The .NET MAUI/WinForms/WPF BlazorWebViews can now all load static assets from a custom IFileProvider.
Each platform's BlazorWebView control has a new virtual method:
To serve custom static assets, create a derived BlazorWebView that overrides the new
CreateFileProvider
method to return custom assets:This PR includes samples for each platform that shows how to serve static files from an "in-memory" storage.