I am building my App completely with Blazor. Everything happens inside my BlazorWebView. Is it possible to use things like RefreshView
inside a .razor file? I know I can instantiate a ContentView
from code behind but can I implement it into the page?
Asked
Active
Viewed 588 times
7

Fabian Kracher
- 83
- 7
1 Answers
7
I know this is an old question, but here is my solution if anyone may find it useful. If there is an easier way to do this, feel free to comment.
In the MainPage.xaml I surrounded the BlazorWebView with a RefreshView:
<RefreshView x:Name="RefreshView" Refreshing="RefreshView_Refreshing">
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</RefreshView>
In the event handler I attempt to make a call to the base class of all razor pages:
void RefreshView_Refreshing(object sender, EventArgs e)
{
if (RefreshablePageBase.Current?.NavigationManager != null)
{
var navigationManager = RefreshablePageBase.Current.NavigationManager;
navigationManager.NavigateTo(navigationManager.Uri, true, true);
RefreshView.IsRefreshing = false;
}
}
And I attempt to use this base class for all razor pages:
using Microsoft.AspNetCore.Components;
namespace GotchaFitness.Razor.Pages;
public abstract class RefreshablePageBase : ComponentBase
{
public static RefreshablePageBase Current;
[Inject]
public NavigationManager NavigationManager { get; set; }
protected RefreshablePageBase()
{
Current = this;
}
}

Martin Lottering
- 1,624
- 19
- 31
-
1Worked really well! If anyone is wondering the syntax for the razor pages to inheirt the RefreshablePageBase class it's: @inherits RefreshablePageClass; Remember to include the using statement for your namespace too. – Derek J. Aug 16 '23 at 04:51
-
Works great, fantastic! – Palanikumar Aug 27 '23 at 12:55