AvaloniaCommunity / Prism.Avalonia

Prism Avalonia UI framework. Super charge your cross-platform apps with IoC, navigation, and more! Sponsored by Suess Labs. Prism is based on Microsoft patterns and practices.
https://www.nuget.org/packages/Prism.Avalonia/
MIT License
313 stars 40 forks source link

RegisterViewWithRegion enhancements #210

Open Coolkeke opened 2 months ago

Coolkeke commented 2 months ago

Description

I have a practical need. In the project module development, I need to use the RegisterViewWithRegion method in Prism. However, the current method cannot let me know that my view has been successfully initialized and navigated, and I cannot pass parameters to the current page after the interface is initialized. I found that the RequestNavigate method can be passed, but there is a difference between RequestNavigate and RegisterViewWithRegion. RequestNavigate can only be used and pass parameters after the view is constructed. RegisterViewWithRegion can only initialize and navigate to the current view, and cannot pass parameters or trigger OnNavigatedTo. I don’t know if there is a method in the framework that can trigger a method similar to OnNavigatedTo after calling the RegisterViewWithRegion method to complete a basic page initialization loading method. This method is used to load data on the server.

Context

I now have a temporary solution, which is to call getContentDelegate in RegisterViewWithRegion to complete the method of getting data from the server.

public void OnInitialized(IContainerProvider containerProvider)
{
    var Region = containerProvider.Resolve<IRegionManager>(); 
    Region.RegisterViewWithRegion(SystemResource.Root, provider =>
    {
        var main = provider.Resolve<Main>();
        if (main.DataContext is MainViewModel vm) vm.Init();
        return main;
    });
}

public void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterForNavigation<Main, MainViewModel>(nameof(Main));
}

Is there any other more elegant solution? If not, can the framework support adding the actual functional requirements I proposed to expand the robustness of the current framework?