Skip to content
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

[WIP] fix: Adjusting activation to occur once the content loads #2600

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Navigation.Toolkit/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static void ApplyLoadingTask(this Window window, FrameworkElement root,
loadingTask = new Func<Task>(async () =>
{
await navInit;
window.Activate();
window.ActivateWhenReady();
})();
}
}
Expand All @@ -64,7 +64,7 @@ internal static void ApplyLoadingTask(this Window window, FrameworkElement root,
if (activate)
{
// Activate immediately to show the splash screen
window.Activate();
window.ActivateWhenReady();
}
}
}
10 changes: 7 additions & 3 deletions src/Uno.Extensions.Navigation.UI/ServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Uno.Extensions;

/// <summary>
/// Extension methods on <see cref="ServiceProvider" />.
/// </summary>
public static class ServiceProviderExtensions
{
/// <summary>
Expand Down Expand Up @@ -46,7 +49,7 @@ internal static IServiceProvider CreateNavigationScope(this IServiceProvider ser
.CloneScopedInstance<IDispatcher>(services);
}



/// <summary>
/// Initializes navigation for an application using a ContentControl
Expand Down Expand Up @@ -122,11 +125,12 @@ private static async Task<IHost> BuildAndInitializeHostAsync(

await Task.Run(() => host.StartAsync());

// Fallback to make sure the window is activated
window.Activate();
window.ActivateWhenReady();

await startup;

return host;
}

private static void Content_Loaded(object sender, RoutedEventArgs e) => throw new NotImplementedException();
}
34 changes: 34 additions & 0 deletions src/Uno.Extensions.Navigation.UI/WindowExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Uno.Extensions;

/// <summary>
/// Extension methods on <see cref="Window" />.
/// </summary>
public static class WindowExtensions
{
/// <summary>
/// Activates the window when the content is ready
/// </summary>
/// <param name="window">The <see cref="Window" /> to activate</param>
public static void ActivateWhenReady(this Window window)
{

if (window.Content is FrameworkElement content)
{
if (content.IsLoaded)
{
// Fallback to make sure the window is activated
window.Activate();
}
else
{
content.Loaded += (_, _) => window.Activate();
content.SizeChanged += (_, _) => window.Activate();
content.Loading += (_, _) => window.Activate();
}
}
else
{
window.Activate();
}
}
}
Loading