Closed geelapidus closed 1 year ago
Tested it, unfortunately it seems this is the behavior of the underlying BlazorWebView, changing the HostPage property has no effect after initialization of the view. So it seems this is only ever used at startup, to point to the index.html of your embedded SPA.
Maybe if you tell me what you're trying to accomplish I could figure out your options. E.g. if you just want to display an external website in your application, a plain WebView2 component would be a better fit than my BlazorWebView
HI, I agree with you . A possible work around is creating/deleting the webview each time the hostpage has been changed. For that I use a template like the following :
<DockPanel > <ItemsRepeater ItemsSource="1"> <ItemsRepeater.ItemTemplate> <DataTemplate> <Border Margin="0,0,0,0"> <BlazorWebViewTemplate/> </Border> </DataTemplate> </ItemsRepeater.ItemTemplate> </ItemsRepeater> </DockPanel>
In the code in BlazorWebViewTemplate.cs :
internal class BlazorWebViewTemplate : IDataTemplate {
string hostpage = "http://cnn.om";
double zoomFactor = 1;
int width = 800;
public BlazorWebViewTemplate() : base() {
}
public Control Build(object param) {
MainWindow view = MvvmConnection.GetMvvmConnection().Item1 as MainWindow;
var blazor = new BlazorWebView {
HostPage = hostpage,
ZoomFactor = zoomFactor,
Width = width,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Stretch,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
Services = view.services,
RootComponents = view.rootComponents
};
return blazor;
}
public bool Match(object data) {
if (data != null) {
return true;
} else {
return false;
}
}
I hope the idea is not so bad. The control is created but is not rendered probably because I'm not experienced in Avalonia. Thanks. Gennady.
Hi, today I faced an issue - the blazor webview shows only the content by Url that was set in XAML. I tried to use binding of HostPage and got "Unable to use suitable getter or adder ..." . I tried both string and string? types. If I force to set a new value to HostPage by the code , nothing happens or the message of "There is no content at " is returned. Thank you.