Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Is it possible to use Prism INavigationService in a custom view?

$
0
0

I made a custom view that extends ContentView, and I would like to use the NavigationService to handle navigation, but when I inject it in the constructor, I get this build error (apparently in CustomHeader.xaml):

Severity Code Description Project File Line Suppression State
Error The given key was not present in the dictionary.

This is my custom view code behind (CustomHeader.xaml.cs):

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class CustomHeader : ContentView
    {
        private DelegateCommand _profilePictureTappedCommand;
        public DelegateCommand ProfilePictureTappedCommand =>
            _profilePictureTappedCommand ?? (_profilePictureTappedCommand = new DelegateCommand(ExecuteProfilePictureTappedCommand));

        // This Prism command works just fine, it fires successfully
        private void ExecuteProfilePictureTappedCommand()
        {
        }

        public CustomHeader(INavigationService navigationService)
        {
            try
            {
                InitializeComponent();

                ProfilePicture = Properties.CurrentUser.ProfilePicture;
            }
            catch (Exception ex)
            {
                throw;
            }

            _navigationService = navigationService;
        }
    }

Is it not possible to do dependency injection in a class that extends ContentView?
Just tagging you @BrianLagunas in case you have a quick answer to that.

Thanks!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>