How to register a page to the Wpf.Ui.Mvvm.Contracts.IPageService service #432
-
Hello, I am using the mvvm design pattern with the Wpf.Ui visual studio extension and every time I try to navigate to a page I created in the Compact Navigation project template I get the following error -> System.InvalidOperationException: 'The UiDesktopApp1.Views.Pages.EditorPage has not been registered in the Wpf.Ui.Mvvm.Contracts.IPageService service.' There are no other errors and my page is set up exactly like the DashboardPage that comes with the template `<ui:UiPage xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" x:Class="UiDesktopApp1.Views.Pages.EditorPage"
</ui:UiPage> ` ` public partial class ContainerViewModel : ObservableObject
} ` I have looked everywhere in the project to find something I may missed but no luck, and I'm starting to get a bit frustrated, Thank you for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @Quinton619, demo applications and extension templates use the dependency injection mechanism to manage page instances. As the error indicates, Each Page or ViewModel is treated as a service. In the case of WPF UI templates, pages are registered in public partial class App
{
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
// Register EditorPage class as service, which is instantiated only once
services.AddSingleton<UiDesktopApp1.Views.Pages.EditorPage>();
}).Build();
} This allows the |
Beta Was this translation helpful? Give feedback.
Hey @Quinton619, demo applications and extension templates use the dependency injection mechanism to manage page instances. As the error indicates,
IPageService
does not know that theUiDesktopApp1.Views.Pages.EditorPage
page has been registered.Each Page or ViewModel is treated as a service. In the case of WPF UI templates, pages are registered in
App.xaml.cs
.