0
votes

I updated to 7.2 and I'm trying to use the DialogService. In following the example in the release notes, it seems that if the view is based on Grid it cannot be registered with the container (Unity). If I change the view to be a ContentPage I can get it to register with the container but when I run my test and tap a button that should launch the dialog via ShowDialog, I get the following error:

Specified cast is not valid.
  at Prism.Services.Dialogs.DialogService.CreateViewFor (System.String name) [0x00000] in d:\a\1\s\Source\Xamarin\Prism.Forms\Services\Dialogs\DialogService.cs:154 
  at Prism.Services.Dialogs.DialogService.ShowDialog (System.String name, Prism.Services.Dialogs.IDialogParameters parameters, System.Action`1[T] callback) [0x00044] in d:\a\1\s\Source\Xamarin\Prism.Forms\Services\Dialogs\DialogService.cs:31

I'm not sure what is going wrong. The only difference in my code is that my test button is in a contentpage in a tabbedpage.

I think the docs need to be updated with an example that works.

Thanks for any help.

1
Well, I think I figured out what was wrong. When I added my dialog view I just used a contentpage template and it added a registration with the container at the end of a long list of registrations. I manually added a registration and I guess this cause some issues. - jmichas
Hi , if solved remember to update in answer , then others will know the solution . - Junior Jiang

1 Answers

1
votes

Dialogs must derive from type View. Since the RegisterDialog extension is strongly typed it enforces this. If you've circumvented the registration or instead used RegisterForNavigation then the issue is entirely that you're doing it wrong.

The error that you've reported here is that when the View is created for the Dialog it cannot cast it to type View.

Note that in your App.RegisterTypes you would have something like:

containerRegistry.RegisterDialog<DialogA>();