0

I am writing a small WPF application and using Prism 7.1. It seems that everything worked, but the only _regionManager.RequestNavigate() does not work. When I click a button which binding to DelegateCommand, _regionManager.RequestNavigate() was called but nothing happens. This is an image when I use an overload of RequestNavigate() which has a navigationCallback parameter, NavigationService is null:

enter image description here

_regionManager is assigned from the constructors. This happens not only one place, all calls to _requestManager.RequestNavigate() still like that.

This is how I setup:

App.xaml.cs:

public partial class App: PrismApplication 
{
    protected override void OnStartup (StartupEventArgs e) 
    {
    base.OnStartup (e);
    }

    protected override void RegisterTypes (IContainerRegistry containerRegistry) 
    {
        containerRegistry.RegisterForNavigation<DangNhapView> ();

        containerRegistry.RegisterSingleton<IBusyMonitor, CompositeMainComponentsBusyMonitor> ();
        containerRegistry.RegisterSingleton<INetRequester, HttpNetService> ();
        containerRegistry.RegisterSingleton<IInternetConnectionChecker, MNBConnectionChecker> ();

    }

    protected override Window CreateShell () 
    {
        return Container.Resolve<MainWindow> ();
    }

    protected override void ConfigureModuleCatalog (IModuleCatalog moduleCatalog) {

    }
}

MainWindow.xaml:

<Window x:Class="XemDiemSinhVienMain.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:XemDiemSinhVienMain.Views"
        mc:Ignorable="d"
        Title="Xem điểm sinh viên" Height="520" Width="940"
        xmlns:prism="http://prismlibrary.com/"
        prism:ViewModelLocator.AutoWireViewModel="True"
        xmlns:uc="clr-namespace:XemDiemSinhVien.Infrastructures.UserControls;assembly=XemDiemSinhVien.Infrastructures"
        xmlns:constants="clr-namespace:XemDiemSinhVien.Infrastructures.Constants;assembly=XemDiemSinhVien.Infrastructures"
        xmlns:xemDiemSinhVienMain="clr-namespace:XemDiemSinhVienMain"
        Icon="../app_icon.ico">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="1"
                      CornerRadius="0"
                      CaptionHeight="0"
                      UseAeroCaptionButtons="False"
                      ResizeBorderThickness="5"/>
    </WindowChrome.WindowChrome>
    <!-- https://stackoverflow.com/questions/2967218/window-out-of-the-screen-when-maximized-using-wpf-shell-integration-library/2975574 -->
    <Window.Template>
        <ControlTemplate TargetType="{x:Type local:MainWindow}">
            <Border BorderBrush="Green">
                <Border.Style>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="BorderThickness" Value="0"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=WindowState}" Value="Maximized">
                                <Setter Property="BorderThickness" Value="8"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <!-- Window's content -->
                <Grid Background="White"> 
                    <Grid.RowDefinitions>
                        <RowDefinition Height="32"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <ContentControl Grid.Row="1"
                                    prism:RegionManager.RegionName="{x:Static constants:RegionNames.MainContentRegion}"/>
                    <Button Content="Switch to NavigationTestView"
                            Command="{Binding SwitchToNavigationTestViewCommand}"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Top"
                            Margin="10"
                            Grid.Row="1"/>
                    <uc:WindowTitleBar Grid.Row="0"
                                       MinimizeClick="WindowTitleBar_OnMinimizeClick"
                                       CloseClick="WindowTitleBar_OnCloseClick"
                                       MouseLeftButtonDown="WindowTitleBar_OnMouseLeftButtonDown"/>
                </Grid>
            </Border>
        </ControlTemplate>
    </Window.Template>
</Window>

MainWindowViewModel:

public class MainWindowViewModel : BindableBase 
{
    private IRegionManager _regionManager;
    public DelegateCommand SwitchToNavigationTestViewCommand { get; private set; }

    public MainWindowViewModel (IRegionManager regionManager) {
        _regionManager = regionManager;

        SwitchToNavigationTestViewCommand = new DelegateCommand (() => {
            _regionManager.RequestNavigate (RegionNames.MainContentRegion, "DangNhapView");
        });
    }
}

So how can I fix this problem? Thank you for reading my question.

namhnz
  • 75
  • 1
  • 10
  • Did you setup `RegisterViewWithRegion` properly? see also [prism navigation docs](http://prismlibrary.github.io/docs/wpf/legacy/Navigation.html#prism-region-overview) – Jan Paolo Go Apr 02 '19 at 14:52
  • What's in `result`? An exception in there should give you a hint. Also, did you register the view for navigation (like `containerRegistry.RegisterForNavigation();`)? – Haukinger Apr 02 '19 at 14:58
  • @PaoloGo If I use RegisterViewWithRegion, the content load properly. The issue only happens with RequestNavigate. – namhnz Apr 02 '19 at 15:15
  • @Haukinger Of course I used RegisterForNavigation for views which I want to navigate. I also make a ViewBView only without any logic to test, but I can't navigate to ViewBView. – namhnz Apr 02 '19 at 15:19
  • @Haukinger This is what inside Uri: https://imgur.com/a/5zL7KUT AbsoluteUri = 'result.Context.Uri.AbsoluteUri' threw an exception of type 'System.InvalidOperationException' – namhnz Apr 02 '19 at 15:25
  • @namhnz `result` is interesting, can you tell us what's in there? You show no code or exception, that makes a question rather difficult to answer, we can just guess what's wrong. – Haukinger Apr 02 '19 at 15:27
  • @Haukinger Hope this can show useful information, this is result in Watch window: https://imgur.com/a/9R8GwhH – namhnz Apr 02 '19 at 15:44
  • 1
    @namhnz that doesn't tell me anything. Please edit your question to show the relevant code, i.e. your registrations, your views, your view models including the navigation commands... – Haukinger Apr 02 '19 at 15:51
  • 1
    This sounds a little like a problem I had and documented here: https://stackoverflow.com/questions/44577082/prism-6-region-manager-requestnavigate-fails-to-navigate-for-some-regions – Rob Goodwin Apr 24 '19 at 16:09

0 Answers0