简体   繁体   中英

WPF, How Prism link Views and URI

I'm learning Prism and I don't understand how the navigation is done with the URI. In this documentation example , the code on github use:

private void Button_Click(object sender, RoutedEventArgs e)
{            
    this.regionManager.RequestNavigate(RegionNames.MainContentRegion, calendarViewUri);
}

The URI is declared like this:

private static Uri calendarViewUri = new Uri("CalendarView", UriKind.Relative);

There is a CalendarView.xaml declared, in the code, but how the link is done? Is Prism just look at the URI and try to find a matching view name then load it into the region?

If my assumption is correct, there is no need to register the link between the URI and the View. But what if a view is renamed, that means the navigation will be broken, am I right?

For the "missing link", look at ViewSwitchingNavigation.Calendar/CalendarModule.cs , this is where the calendar module is initialized, ie where it makes all its stuff known to the rest of the application:

this.unityContainer.RegisterTypeForNavigation<CalendarView>();

This basically says " when asked to navigate to 'CalendarView' , create an instance of CalendarView ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM