• Home
  • Documentation
Show / Hide Table of Contents
  • Introduction
  • Getting Started
    • Download and Setup Prism
    • NuGet Packages
    • Productivity Tools
  • Commands
    • Commanding
    • Composite Commands
  • Dependency Injection
    • Getting Started
    • Registering Types
    • Platform Specific Services
    • Exception Handling
    • ContainerLocator
    • Adding a Custom Container
    • Appendix
  • Event Aggregator
  • ViewModelLocator
  • Modules
  • WPF / Uno
    • Introduction
    • Getting Started
    • Converting From Prism 7.x
    • Converting From Prism 6.x
    • View Composition
    • Region Navigation
      • About Navigation in Prism
      • Basic Region Navigation
      • View/ViewModel Participation
      • Navigating to Existing Views
      • Passing Parameters
      • Confirming Navigation
      • Controlling View Lifetime
      • Navigation Journal
    • Interactivity
      • Event To Command
    • Dialog Service
    • Advanced
      • Region Adapters
    • Legacy (Prism 6)
      • Introduction
      • Initializing
      • Managing-Dependencies
      • Modules
      • Implementing-MVVM
      • Advanced-MVVM
      • Composing-the-UI
      • Navigation
      • Communication
      • Deploying
      • Appendix-A-Glossary
      • Appendix-B-Patterns
      • Appendix-C-Prism-Library
      • Appendix-D-Extending-Prism
      • Appendix-E-Click-Once
  • .NET MAUI
    • Getting Started
    • Migrating from Prism.Forms
    • PrismAppBuilder
    • Dependency Injection
    • AppModel
      • IPageLifecycleAware
    • Behaviors
      • Introduction
      • BehaviorBase<T>
      • EventToCommandBehavior
      • PageBehaviorFactory
    • Dialogs
      • Getting Started
      • IPageDialogService
      • IDialogService
    • Navigation
      • Introduction
      • Page Navigation
      • NavigationBuilder
      • Understanding the INavigationResult
      • NavigationExceptions
      • Global Navigation Observer
      • XAML Navigation
    • Regions
      • Introduction
  • Xamarin.Forms
    • Create Your First App
    • Behaviors
      • Working with Behaviors
      • EventToCommand Behavior
      • PageBehaviorFactory
    • Dialogs
      • Dialogs
      • Page Dialog Service
      • Dialog Service
      • Styling Dialogs
    • Navigation
      • Navigation Basics
      • Passing Parameters
      • Confirming Navigation
      • Deep Linking
      • Working w/ MasterDetailPages
      • Working w/ NavigationPages
      • Working w/ TabbedPages
      • XAML Navigation
    • Application Lifecycle
    • Page Lifecycle
    • Additional Platforms
      • GTK

PageBehaviorFactory

For those coming from Prism.Forms who may have had some previous knowledge of the PageBehaviorFactory, this has been completely re-imagined for Prism.Maui. You can no longer override Prism's Page Behaviors, however it is extremely easy to apply any Behavior to pages in your application and get full Dependency Injection support along the way.

Applying behaviors from the Container

Registering a Behavior to be applied to every page the Navigation Service creates is extremely easy as we provide a new RegisterPageBehavior method on the IContainerRegistry and we have duplicated these extensions on the IServiceCollection as well so you can add these regardless of which context you are in while registering your services.

private void RegisterTypes(IContainerRegistry container)
{
    container.RegisterPageBehavior<MyBehavior>();
}

private void ConfigureServices(IServiceCollection services)
{
    services.RegisterPageBehavior<MyBehavior>();
}

Sometimes though you may want to provide some limits around what pages that your Behavior will be added to. For instance you may want a specific behavior applied only to a NavigationPage but not a ContentPage. In this case you can use the overload for the RegisterPageBehavior method like:

private void RegisterTypes(IContainerRegistry container)
{
    container.RegisterPageBehavior<NavigationPage, MyBehavior>();
}

private void ConfigureServices(IServiceCollection services)
{
    services.RegisterPageBehavior<NavigationPage, MyBehavior>();
}
  • Edit on GitHub
  • Ask questions
  • Follow @PrismLib
  • Follow @BrianLagunas
  • Follow @DanJSiegel
Back to top Copyright 2015-2022 Prism