Skip to content

NavigateCommand & NavigateOnChanged ​

Generate DelegateCommand members that call IRegionManager.RequestNavigate. The ViewModel must already expose an accessible IRegionManager field or property (constructor injection is typical). Generators do not add constructor parameters.

csharp
using Prism.Mvvm;
using Prism.Navigation.Regions; // Prism 9+
// using Prism.Regions;         // Prism 8 (platform assembly)
using Prism.SourceGenerators;

public partial class ShellViewModel : BindableBase
{
    private readonly IRegionManager _regionManager;

    public ShellViewModel(IRegionManager regionManager) => _regionManager = regionManager;

    [NavigateCommand(Region = "Content", Target = "Dashboard")]
    private void GoDashboard() { }
}

Generates GoDashboardCommand calling _regionManager.RequestNavigate("Content", "Dashboard").

Optional attribute properties: CommandName, RegionManagerMember.

Apply to the same field or partial property as [ObservableProperty]:

csharp
[ObservableProperty]
[NavigateOnChanged(Region = "Content", TargetMember = nameof(Key))]
public partial NavigationItem SelectedItem { get; set; }

Generates OnSelectedItemChanged that navigates when the property changes. TargetMember is evaluated on the new value (for example Key).

Prism 8 vs Prism 9 regions ​

PrismINavigationAware / IRegionManager namespace
9+Prism.Navigation.Regions (in Prism.Core for IRegionManager; INavigationAware may also come from the platform package)
8Prism.Regions (in Prism.Wpf, Prism.Avalonia, etc.—not in Prism.Core alone)

[NavigationAware] picks the namespace present in the compilation. Region navigation generators use the same resolution.

Diagnostics ​

IDWhen
PSG7001No accessible IRegionManager member
PSG7002[NavigateCommand] missing Region
PSG7003[NavigateCommand] missing Target
PSG7004[NavigateOnChanged] without [ObservableProperty]
PSG7005[NavigateOnChanged] missing TargetMember

Released under the MIT License.

Released under the MIT License.