-
As Maui GA is coming up, are there any plans to support Hot Reload for Markup in the future? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
@danielftz the Hot Reload should work with the Markup package, since it's just C# code. |
Beta Was this translation helpful? Give feedback.
-
Hey Gang! Quick update - I am meeting Microsoft's C# Hot Reload team next week to discuss this issue. Hopefully they'll give us some insight into best practices around supporting Hot Reload, and, if so, I'll be able to submit a PR adding Hot Reload support 🤞 |
Beta Was this translation helpful? Give feedback.
-
I want to take benefit of C# Hot Reload to build C# UI. So, I put the Content under Build Method like void Build()=>Content= new Grid {};
In the same way as in the C# UI and .NET Hot Reload - A Match Made in .NET MAUI - DEV Community , I define the build method in constructor of the contentpage. Than call it from the OnNavigatedTo(). I can't find out the mistake in my approach. |
Beta Was this translation helpful? Give feedback.
-
C# Hot Reload support is finally here! Well...almost - the PR is open!! #232 Check out the PR and let me know what you think! One downside of C# Hot Reload is that it doesn't update the visible .NET MAUI UI for us automatically. It will update the underlying C# code, but something needs to tell .NET MAUI to reload the page. You could always click C# Hot Reload in Visual Studio, then navigate away from the current page, and navigate back to it to see the changes. But we can't tell .NET MAUI to invalidate the current page/view, the .NET MAUI engineering team would need to bake that feature into the framework. Since every app is different, we think it's best in this initial release to defer to the user to update their own UI. To handle the Hot Reload event yourself, you just need to implement builder.Services.AddSingleton<ICommunityToolkitHotReloadHandler, MyHotReloadHandler>(); I've included this example in the Sample App that we'll include in the official documentation as a starting point for devs looking to implement using System.Diagnostics.CodeAnalysis;
namespace CommunityToolkit.Maui.Markup.Sample;
class HotReloadHandler : ICommunityToolkitHotReloadHandler
{
public async void OnHotReload(IReadOnlyList<Type> types)
{
if (Application.Current?.MainPage is not Page mainPage)
{
return;
}
foreach (var type in types)
{
if (type.IsSubclassOf(typeof(Page)))
{
if (mainPage is AppShell shell)
{
var visiblePage = shell.CurrentPage;
await mainPage.Dispatcher.DispatchAsync(async () =>
{
await Shell.Current.GoToAsync(type.Name, false);
Shell.Current.Navigation.RemovePage(visiblePage);
});
break;
}
else
{
if (TryGetModalStackPage(out var modalPage))
{
await mainPage.Dispatcher.DispatchAsync(async () =>
{
await mainPage.Navigation.PopModalAsync(false);
await mainPage.Navigation.PushModalAsync(modalPage, false);
});
}
else
{
await mainPage.Dispatcher.DispatchAsync(async () =>
{
await mainPage.Navigation.PopAsync(false);
await mainPage.Navigation.PushAsync(modalPage, false);
});
}
break;
}
}
}
}
static bool TryGetModalStackPage([NotNullWhen(true)] out Page? page)
{
page = Application.Current?.MainPage?.Navigation.ModalStack.LastOrDefault();
return page is not null;
}
} |
Beta Was this translation helpful? Give feedback.
C# Hot Reload support is finally here! Well...almost - the PR is open!! #232
Check out the PR and let me know what you think!
One downside of C# Hot Reload is that it doesn't update the visible .NET MAUI UI for us automatically. It will update the underlying C# code, but something needs to tell .NET MAUI to reload the page.
You could always click C# Hot Reload in Visual Studio, then navigate away from the current page, and navigate back to it to see the changes. But we can't tell .NET MAUI to invalidate the current page/view, the .NET MAUI engineering team would need to bake that feature into the framework.
Since every app is different, we think it's best in this initial release to defer …