TemplateStudio icon indicating copy to clipboard operation
TemplateStudio copied to clipboard

[Prism] Some viewmodels don't follow Prism's VM based navigation to load data

Open bartlannoeye opened this issue 6 years ago • 8 comments

Expected Behavior

Data should be loaded in the OnNavigatedTo method

    public override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> viewModelState)
    {
        base.OnNavigatedTo(e, viewModelState);
        await _cameraControl.InitializeCameraAsync();
    }

Actual Behavior

These page/viewmodel combinations start from the page's code behind and call a method in the viewmodel like following piece of code passing in navigation parameters.

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        await ViewModel.InitializeAsync(e.Parameter as string, e.NavigationMode);
        showFlipView.Begin();
    }
  • ImageGallery
  • ImageGalleryDetail

System

  • VS Version: 15.8.5
  • WTS Wizard Version: 2.4.18260.1
  • WTS Template Version: 2.4.18260.1
  • Windows Build:

bartlannoeye avatar Oct 07 '18 22:10 bartlannoeye

I created a new WTS solution to check. Select Navigation Pane then Next. Select Prism, then Next then Create. You will see that even the ShellPage.xaml.cs has OnNavigatedTo() and trying to call the ViewModel.Initialize().

After that test, I added every type of page template that WTS supports and examined them. The following views are calling some form of ViewModel initialize function from either the ctor or OnNavigatedTo() in the code behind in the view: CameraPage, ImageGalleryDetailPage, ImageGalleryPage, InkDrawPage, InkDrawPicturePage, InkSmartCanvasPage, MediaPlayerPage, ShellPage, WebViewPage. If, while using Prism, referencing the ViewModel in this way is never acceptable, then all those will need to be re-examined.

The following pages do not call the ViewModel from within the view's code behind: ChartPage, DataGridPage, MainPage, MapPage, MasterDetailPage, SettingsPage, TabbedPage, TelerikDataGridPage.

mjmeans avatar Oct 08 '18 22:10 mjmeans

There's a difference in why the view calls the viewmodel. In case of drawing, I don't think we can easily get around. But I'll have a look at every single one of them in detail and see if there are other ways to work with them.

More important is that navigation and passing navigation parameters should be done through the viewmodels.

bartlannoeye avatar Oct 09 '18 05:10 bartlannoeye

The Prism project has abandoned UWP, per Brian Lagunas. The NuGet packages for UWP have been removed and UWP is marked as deprecated. PrismLibrary

PaulaScholz avatar Apr 27 '19 22:04 PaulaScholz

The Prism project has abandoned UWP, per Brian Lagunas. The NuGet packages for UWP have been removed and UWP is marked as deprecated.

It's still listed as supported on their site and the packages have not been removed. Its future is uncertain but it's not gone yet.

mrlacey avatar Apr 27 '19 23:04 mrlacey

PrismUWPRemoved

version 6.3 is the last supported build

PaulaScholz avatar Apr 27 '19 23:04 PaulaScholz

@PaulaScholz WTS uses the Prism.Windows package (v6.3) and that hasn't been removed from NuGet. We are aware of the plans by the Prism team to not continue to actively develop for UWP but there were plans for Template10 to take over. At the moment nothing is final and the impact on WTS is not certain yet. Additionally, it does not have a great impact on this issue which is about the inconsistency of navigation and data passing.

mrlacey avatar Apr 27 '19 23:04 mrlacey

@mrlacey I hope the Prism team moves forward with UWP because I love developing with UWP and Prism 6.3 actually works for UWP Suspend/Resume. It will be a shame if they do finally decide to move on without it.

PaulaScholz avatar Apr 28 '19 00:04 PaulaScholz

@PaulaScholz aside from a few minor issues, v6.3 is a stable release and can still be used.

It is true that the work on integrating (read: completely base on) Template 10 and bring a v7 for UWP has been halted as there was no test coverage, a lot of static methods and some other things the Prism team didn't want to release as v7.

We're currently evaluating the best way forward, but until then there's no "beta" v7 based on an old code base.

bartlannoeye avatar Apr 28 '19 05:04 bartlannoeye