Reputation: 45
I have the basic Prism/Unity/Xamarin Forms app from the Prism Templates.
If I change the following (add parameter) it fails
public MainPage(INavigationService navigationService)
{
InitializeComponent();
}
container works but getting the navigation service this way causes MainPage to not be found.
Is there a better way for a ContentPage to get the navigation service so a button click can navigate to a new page?
I have also tried to register the navigation service from the OnInitialized as I have found in some samples and that is a compile error now.
Using following packages/versions:
Upvotes: 2
Views: 466
Reputation: 10015
Prism is a framework to help you create your apps by using MVVM. If you go read up on MVVM and the practices used, you'll notice that code behind in your page should be kept to a minimal and the logic is moved to the viewmodel.
Applying this to your code, you should NOT add the INavigationService
to your page, as navigation should be done from the viewmodel.
Now I hear you asking: "but how do I get from my click to the viewmodel?". That's done by using a command.
<Button Text="Navigate to speak page" Command="{Binding NavigateToSpeakPageCommand}" />
I suggest you have a look at the documentation and samples on the Prism repository:
Upvotes: 2