I use Modern UI in my project. Unfortunately, its navigation mechanics are based on absolute (or relative to project directory) paths to views' xaml files.
Example window xaml
...
<mui:LinkGroup DisplayName="Menu">
<mui:LinkGroup.Links>
<mui:Link DisplayName="About"
Source="/View/Pages/AboutView.xaml"/>
<mui:Link DisplayName="Settings"
Source="/View/Pages/SettingsView.xaml"/>
<mui:Link DisplayName="Gallery"
Source="/View/Pages/GalleryView.xaml"/>
</mui:LinkGroup.Links>
</mui:LinkGroup>
...
Example code behind
string url = "/View/Pages/AboutView.xaml";
NavigationService nav = NavigationService.GetNavigationService(this);
nav.Navigate(new System.Uri(url, UriKind.RelativeOrAbsolute));
I like to refactor a lot, so I don't want to rely on hardcoded paths to source files. I've been thinking maybe a global dictionary-like structure that maps class types typeof(XyzViewModel)
to their respective paths would be a neat idea (at least I'd have everything in one place), but then again, singletons are evil. I don't think reflection is an answer too.
Is there a way to handle this situation without resorting to anti-patterns?