Is this a correct way of Navigating a Page inside of a Frame, which also in another Page Frame? (WPF)

Viewed 43

So in this image, which contains a frame, where pages should show (Pages with Current Display are current source of Parent Page)

enter image description here

and I found this repository, just to use the navigation service however, it only uses RootFrame. so I made some changes

// INavigationService.cs
interface INavigationService
{
    string CurrentPageKey { get; }

    void GoBack();
    void NavigateTo(string frame, string pageKey);
    void NavigateTo(string frame, string pageKey, object parameter);
}

// FrameNavigationService.cs
public virtual void NavigateTo(string frameName, string key, object parameter)
{
    ...

    if(GetDescendantFromName(Application.Current.MainWindow, frameName) is Frame frame)

    ...
}

and used this code:

// MainViewModel
public RelayCommand LoadPage1Command 
            => loadPage1Command ?? (loadPage1Command = new RelayCommand(() => navigationService.NavigateTo("Page1")));

// Page1ViewModel
public RelayCommand LoadedCommand
            => loadedCommand ?? (loadedCommand = new RelayCommand(() => navigationService.NavigateTo("Page1_Frame", "Page1_1")));

I can't tell if that's the way of navigating a page inside of a frame. Are there any behavior design patterns I could use as alternative to this if the modified code is bad?

0 Answers
Related